Posted under » Ubuntu » Apache » LAMP Security on 25 June 2013
If you get a file permission error while using Apache, it is most probably because www-data is not able to access the file. The file owner is probably you, "webmasta" for example but "www-data" need to access to it too. If redhat, instead of www-data, it is apache. You can see determine by "cat /etc/group".
For security, www-data need only to access the file without the need to write or execute. So this is how it is done with much reference to this.
As root
usermod -G www-data -a 'webmasta' chown webmasta /var/www -R chgrp www-data /var/www -R
As user webmasta, only owner can write.
chmod 754 /var/www -R
If you have more than one webmaster, then you have to loosen this a bit like 774 for example.
Please take note that you will sometimes create a folder on the www root folder under webmasta and it will cause a "no priviledge" error. You have to make sure www-data is able to read it by doing this again.
chgrp www-data /var/www -R