Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want anyone in group www-data to have write access to /var/www. For example, if 'a' and 'b' are in group www-data and 'a' creates a file in /var/www - then 'b' will be able to edit it.

The problem is that I create files that PHP and Apache can't edit - and they create files I can't edit without sudo. Both PHP and myself are in www-data group.

I changed the umask setting /etc/profile from umask 022 to umask 002. Is this a safe and proper way to handle this?

Update: Even after changing /etc/profile and restarting the computer PHP still creates files with permission -rw-r--r--.

share|improve this question
Have you set the sticky (sgid) bit on /var/www? – janmoesen Mar 21 '10 at 21:10
How do I set the sticky bit? – Xeoncross Mar 22 '10 at 1:04
up vote 2 down vote accepted

The apache startup script resets everything when apache is started on Debian/Ubuntu. On a Debian/Ubuntu system you should update your umask by adding your umask command to /etc/apache2/envvars. You may also need to change the permissions on the directories under /var/www to 2775. This will force new files that are created to be owned by the group that owns the directory instead of the default group for that user.

share|improve this answer
So would the command be chmod -R 2775 /var/www? – Xeoncross Mar 21 '10 at 23:32
No: that would do the same to files as well as directories - a bad idea. Try: find /var/www -type d -print0 | xargs -0 chmod 2775; that only changes directories and deals with funny characters (blanks etc) in file names. – Jonathan Leffler Mar 22 '10 at 1:02
oops, I already ran it. xD – Xeoncross Mar 22 '10 at 2:10
@Xeoncross: then I recommend running something like: find /var/www -type f -print0 | xargs chmod 664. Most of the files under there should not be executable - possibly all (it depends where your cgi-bin directory is, for example). – Jonathan Leffler Mar 22 '10 at 2:52

Your Answer


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.