Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

our apache runs as www-data:psacln

if this line is run;

<?php file_put_contents("./file.txt","");

then apache creates this file without write permission to the group,

-rw-r--r-- 1 www-data psacln    9 2010-02-25 16:17 file.txt

How can I set our ubuntu/apache so that it gives the group write permission by default upon creating files/folders within web sites?

share|improve this question
up vote 5 down vote accepted

Like DaveG mentions, you can use umask() to change the default permissions of all files created by your process. Your current umask is probably 0022. If you set it to 0002, your file will have the same permissions for both user and group.

You can also modify the permissions of the file you set individually using chmod() This way, you can just run chmod("./file.txt", 664) and your file with be rw for both user and group.

More info on php umask:

More info on php chmod:

share|improve this answer
to clarify a bit more : need to put umask 012 to /etc/init.d/apache2 or to /etc/apache2/envvars – Devrim Mar 1 '10 at 22:55

Set the umask within php using the umask() call:

share|improve this answer

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.