Forum Moderators: coopster

Message Too Old, No Replies

Recommended Apache Group and file permissions

safety precautions

         

willis1480

4:36 am on Jan 18, 2010 (gmt 0)

10+ Year Member



Just curious to what people think about best way to do file writing with apache/php.

Currently I have apache running under the group/user "nobody" (using cpanel WHM). So my web users have to set folder directories they want to write to to 777.

so user "newuser" has all file with user/group of "newuser" in /home/newuser.

To make a folder/files writable, have to set permisions to 777 since the apache user "nobody" is not part of "newuser" group.

Should I just add "nobody" to the "newuser" group?
Should I run everything under "nobody" group?
-Will this give apache access across site? For expample, /home/newuser be able to use php/apache to access /home/newuser2.
Should I just keep things they way they are?

Everyone's input is welcomed. I am a novice(nub) to server management.

lammert

1:25 am on Jan 20, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Are you offering some sort of shared web access for multiple users? In that case opening directories with mask 777 is a very bad solution. It allows the Apache daemon to change, erase and create files in all user directories and also allows users to do the same in the directories of their neighbors.

In general there is no need for apache or php to write in user directories. I have all my HTML and script directories marked as read-only for Apache. One flaw in one PHP script somewhere on your server and some cross-scripting injections will allow a hacker to modify all PHP/HTML files he wants to.

I would at least make all user directories only readable by the Apache process, and blocked for users from the same group. I.e. mask 705 instead of 777. If users need access to some directories from the Apache daemon, they can change permissions to 707 for that specific directory. In no way you should allow that script directories are writable by Apache.

The 0 in 707 and 705 causes that the multiple users in your system can't see the contents of the other users to look for embedded passwords in script files etc.

teamcoltra

1:32 am on Jan 20, 2010 (gmt 0)

10+ Year Member



You know you could install the suphp mod which will allow PHP to run as the user, its slower, but fixes lots of issues

lammert

1:39 am on Jan 20, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



PHP should never be run with user permissions. It creates a wide open door for hackers.