4

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?

Devrim
  • 1,187
  • 4
  • 16
  • 29

2 Answers2

6

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

Kousha
  • 2,040
  • 1
  • 14
  • 10
  • 2
    to clarify a bit more : need to put umask 012 to /etc/init.d/apache2 or to /etc/apache2/envvars – Devrim Mar 01 '10 at 22:55
0

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

DaveG
  • 1,107
  • 6
  • 13