27
20
I am creating a website and part of the function is to write out user generated data with php. I'm using nginx on Ubuntu 13.04. A the moment I'm only testing and everything is served through nginx on locahost.
My php script fails to write the text file (although I can do this manually) and I think it's a permissions problem for writing to my /var/www/example.com/public_html directory.
At the moment I (iain) own this directory but it seems it would make more sense to transfer ownership of the /var/www directory and everything inside that to the www-data user (or should that be group?) and add myself to the www-data group. Is the following the right way to do this?
useradd -G www-data iain
chown -R www-data:www-data /var/www/example.com
chmod 775 /var/www
So does this mean anyone in the www-data group can now read, write and exec in /var/www?
From all the answers regarding
www-data:www-data
, this one solved the issue with missing permissions. Thank you. – Eugene – 2015-10-27T11:53:06.427Ok, I see. Group of /var/www is indeed root:root. Thanks for the link. Does seem more sensible to be in the habit of granting what's required rather than going for convenience. Thanks for the guidance. – duff – 2013-09-16T17:33:12.787
2Ok, so I've just tried to write to /var/www/example.com/public_html with
cp -r php /var/www/example.com/public_html
and I get permission denied. I'm in the www-data group which has rwxrwx--- permissions for this dir. Why is this? – duff – 2013-09-16T17:59:51.280There could be many things here. For example you could not have permission to read some things in php, or you didn't log out and in after usermod (I updated my answer on that point with addgroup to avoid this, and precised where to use sudo). – Calimo – 2013-09-17T08:20:04.833