Page 1 of 1

setting file permissions for fopen, frwrite, etc

Posted: Mon May 31, 2010 2:40 pm
by phpBever
I'm having trouble figuring out how to set the file permissions for the file I want to write to from my php code. The only thing I seem to be able to make work is 777, which seems too permissive.

I don't see any "php user." There's an apache demon user called wwwrun. I made this user part of the user group, but 775 did not work. There are bits and pieces of answers here and there but they don't add up to a clear general statement that helps me.

So if my /srv/www directory is owned by me, DOCUMENT_ROOT is /srv/www/htdocs, the group is 'users', and the directory has 775 permissions, and I want to do this:

Code: Select all

$file =  fopen("$DOCUMENT_ROOT/../orders.txt", "a");
to create and write to a file, what user besides myself and wwwrun needs to be in the 'users' group? Or is this the wrong way to think about it?

Thanks.

Re: setting file permissions for fopen, frwrite, etc

Posted: Tue Jun 01, 2010 2:39 am
by Christopher
You probably want these files to be the user/group of wwwrun. That is what PHP runs as inside the web server. Probably you should add yourself as a member of the wwwrun group.

Re: setting file permissions for fopen, frwrite, etc

Posted: Tue Jun 01, 2010 9:35 am
by phpBever
Good--thanks. That works. Why is that different from having wwwrun in the user group with me as owner and having permissions set to 775? (At least I think that was the setup I tried that didn't work.)