Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I know that the owner of the files in /var/www must be www-data to properly run by apache. But when i run the chown -R www-data:www-data /var/www command i can't the php files in my editor.

How can i edit the files without messing the permissions?

share|improve this question

3 Answers 3

up vote 5 down vote accepted
chown -hR www-data:www-data /var/www

Proper ownership.

chmod  -R g+rw /var/www

This ensures the group can read and write the files, but does not alter other permissions.

find /var/www -type d -ls -exec chmod g+x {} ';'

This ensures the group can list the directories, but does not alter bit x for files.

usermod -aG www-data your-user        

Add yourself to the group www-data so you can use the permissions of this group.

share|improve this answer
3  
+1 and you can also set x for directories only with chmod -R g+rwX /var/www (capital X) on the second step and discard 3rd command –  laurent Jan 14 '12 at 20:45
chown -R www-data:www-data /var/www
chmod  766 /var/www  -R 

This will give write permission to your user.

share|improve this answer
1  
This will give rwx to user (www-data), rw to group (www-data) and `r to others. This won't work to write the file with another user than www-data –  laurent Jan 14 '12 at 20:42
    
My bad , i have updated the answer. –  daya Jan 14 '12 at 20:47
    
Now ok for the access but this will make all the files readable and writable by any user which is not good for security - downvote removed as it works but this is not secure –  laurent Jan 14 '12 at 20:49
    
then make chmod 760 and add yourself to www-data group as a member –  jet Jan 15 '12 at 2:08

The owner of the files does not have be www-data for apache to work well. The requirement is that the apache server which runs as www-data must be able to read the files. Most systems default to allowing group read access, so having the group on the files be www-data is sufficient.

The apache server needs to be able to write dynamic content such as wikis, content upload directories, and caches. Otherwise it is more secure to prevent the apache server from writing its content directories and files.

Consider changing the ownership to the user who needs to modify the content. Add them to the group www-data. You could also set the group sticky bit on the /var/www directory. If you are the user you can execute these commands.

sudo chmod g+s /var/www
sudo usermod -aG www-data $LOGNAME
sudo chown -R $LOGNAME /var/www

Logout and login again to gain access to the www-data group. You will then be able to modify the content.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.