We are using a linux dedicated server in our company.
Whenever we create a folder with php script, apache is owning the folder and each time I have to connect to server via root in order to change the owner to the user and the permissions
But I don’t know which setting I should change in order to fix this.
I tried to switch the safe mode on/off but it didn’t work.
I’d be glad if someone could help me
Thanks in advance
This is a portability issue and depends on your server configuration (i.e. mod_php or FCGI with SuExec).
You can try using the
chownfunction right after you created the file, but that will only work if you know who the actual owner should be (which is not always the case). To overcome this issue, I wrote a simple method that tries to find the best possible file mode that always assures reading and writing (as well as execution for directories) without giving excessive permissions:Basically, if you omit the second
$chmodargument, it will use0777for folders and0666for files by default, however, if PHP is being run under a non-standard user, it will decrement the mode by 22, yielding0755for folders and0644for files. Bare in mind that this will only work for files that already exist, so if you’re creating a directory you’ll need to have additional precautions.