How to give default group write permission to a file created by www-data

apache-2.2file-permissionsumask

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?

Best Answer

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: http://php.net/manual/en/function.umask.php

More info on php chmod: php.net/manual/en/function.chmod.php