How can I give default group write permission to a file created by www-data?
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
Related videos on Youtube
Ryan
Updated on September 17, 2022Comments
-
Ryan over 1 year
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?
-
Ryan about 14 yearsto clarify a bit more : need to put umask 012 to /etc/init.d/apache2 or to /etc/apache2/envvars