When creating per-user php5-fpm pools on an Apache mod_fastcgi setup which of the following is the most secure way and efficient way of granting webserver permissions to the PHP pool?
Option 1:
Set the group to www-data
:
listen.owner = username
listen.group = www-data
listen.mode = 0660
user = username
group = www-data
While this works files created by PHP would have the ownership set to username:www-data while files uploaded via SCP will have username:username.
Option 2:
Add www-data
to the supplementary group username
:
listen.owner = username
listen.group = username
listen.mode = 0660
user = username
group = username
-
usermod -aG username www-data
Which of these options are secure? You may also share a better method.
I checked the following guides:
- http://www.howtoforge.com/php-fpm-nginx-security-in-shared-hosting-environments-debian-ubuntu
- http://www.binarytides.com/php-fpm-separate-user-uid-linux/
But they were all written before bug #67060 was discovered and fixed.
I am using following setup on my LEMP (Nginx + PHP-FPM). For Apache this should also be applicable.
PHP-FPM runs several pools as
nobody:user1
,nobody:user2
...Nginx runs as
nginx:nginx
User
nginx
is a member of eachuser1
,user2
.. groups:File permissions:
(1) User's home dir has no
x
permission forother
, so php-fpm pool running asnobody:user2
will not have access to/home/user1
and vice versa.(2) php script doesn't have
w
forgroup
, so it cannot create files in htdocs.(3) On
uploads
dir we should manually enable write access for groupuser1
, to enable php script to put files there. Don't forget to disable php handler foruploads
, in nginx this is made bybut for Apache you should check.
(4) uploaded files should also have
w
forgroup
if we wantuser1
to be able to edit these files later via ftp or ssh (logging in asuser1:user1
). Php code is also editable via ftp sinceuser1
is itsowner
.Nginx will have
read
access to all users andwrite
access to all user's uploads since usernginx
is a member of eachuser1
,user2
, ... groups. You should not forget to add it to all later groups. You can also modifyuseradd
script to do it automatically.