php5-fpm pools (shared-hosting model)
Is it possible to determine/create php pools for each site? I would like to run every site with custom users and groups and not all with www-data
like: ee site create mysite.com --wp --umyuserr:gmygroup
Then ee create the php-fpm .conf file and the user:group.
I'm doing this manually every time.
@rahul286 If you want to use docker then there are couple of approaches
- combining NGINX & PHP into single container (not recommended)
- by sharing code volumes from php to NGINX running container. (I found this approach useful)
- by sharing host volume with NGINX and PHP containers. (this restricts from scaling application to multiple hosts) I will write and share tutorial on this soon.
I hope EE doesn’t go towards Docker for any reason/usage.
Just an user opinion, for what it’s worth.
@MiteshShah
In Docker-based approach, separation "seems" easy. Maybe you can check with @harshadyeola's method number 2.
@harshadyeola
by sharing code volumes from php to NGINX running container. (I found this approach useful)
I love this approach. Please share more info if you have. :-)
What are you using for MySQL? Remote DB server or separate container with its own data volume?
For shared hosting, we also thought of adding https://github.com/jwilder/nginx-proxy and https://github.com/JrCs/docker-letsencrypt-nginx-proxy-companion
And also give direct SSH access via port mapping to their own container.
@janiosarmento we are exploring Docker and anything this big will take a lot more time. Even if we add docker or anything, the easiness will remain as it is. That being said, can you please help me understand your experience with docker? Is there anything you found that is particularly bad.
@rahul286
What are you using for MySQL? Remote DB server or separate container with its own data volume?
Currently I prefer remote MySQL.
Makes sense. But for shared hosting setup, we might need to provide an option to run MySQL in same VPS.
I had some bad experiences with Docker because it demands a learning time I didn’t have.
My main trouble was mounting volumes outside the container, accessing logs, and so on.
I didn’t try any WordPress Docker approach because of previous bad experiences with other softwares.
@janiosarmento Completely agree on the learning curve!
A reason we haven't added anything related to Docker yet in EE is that after more than a year-long testing and experiments, we are not able to finalize our workflow! :(
So unless we document how we plan to use docker, and open it for feedback, there is no way, it's going to be part of EE core - https://easyengine.io/docs/development-lifecycle/
@MiteshShah @gagan0123 @rahul286 Did anyone evaluate already the pro and cons between using different pools versus per user separated PHP master processes? As far as I understand, APC/Opcache are hold in shared memory per master, so I ask myself, what is better for a shared environment if you have a lot of sites? Should we go with different pools or better with a lot of master-processes? As I googled around, I found restarting php-master-processes is not very 'gracefully' (a long lasting php bug..). Any suggestions from you? Thanks a lot for any comment..
https://bugs.php.net/bug.php?id=60961 https://ma.ttias.be/a-better-way-to-run-php-fpm/
@ingobaab The PHP bug was reported for PHP 5.3 I'm not sure PHP 7.1 was affected due to that bug or not.
AFAIK - When we use same PHP master process and create new pool per website it's still all PHP process owned by www-data master process and its make all website read other users config file easily.
Refer - https://github.com/AnsiPress/AnsiPress/issues/24
I'd first created and found that user1 can easily read user2 wp-config.php file :( For you information in my testing user1 and user2 run on different PHP pool and still read each other wp-config.php file easily
Refer - https://github.com/AnsiPress/AnsiPress/blob/fa1e0a8c6a1cb411571797f7f5225ac5f230dc9f/roles/website/tasks/php.yml#L107
To fix this basic security issue separate PHP master is much better option instead of
- chroot PHP
- separate PHP pool with a single master process.
Hi @MiteshShah,
thank you for your answer, but I think you are wrong here. I testet with different pool-users and I was not able to read anything from another users htdocs directory. In your example you are copying wp.com's "wp-config.php" to php.com's directory and then chown-ing all files to php:php - what do you other expect? Of course you can then read it. If your PHP-Process (master or pool does not matter) runs as wp:wp it could neither copy (read) this file nor change its ownership. Or I am wrong here?
Thank you for your hint with old PHP. Do you or anybody else know if this is still a problem in current PHP-FPM-Implementation?
PS: Are you going to WordCamp Europe (June 15-17)? https://2017.europe.wordcamp.org/tickets/ @rahul286: I want to meet you there :) - I saw that you are a speaker there, great!
@ingobaab Here is my basics/testing ideas
NGINX - www-data user1 - user1:user1 on php pool 9011 user2 - user2:user2 on php pool 9012
Now we had two websites
/home/user1/vhost/user1.com owned by user1:user1 /home/user2/vhost/user2.com owned by user2:user2
In order to nginx read file we need to add nginx user www-data to user1 user2
Now Lets test:
vim /home/user1/vhosts/user1.com/htdocs/read.php
<?php
echo file_get_contents('/home/user2/vhosts/user2.com/wp-config.php');
?>
Open user1.com/read.php and if you see user2 wp-config.php we need to fix that security issue.
@ingobaab Here is my basic idea, I'll test above settings once I'll in front of a laptop and update you soon! If you are free you can test above settings and let us know what you think.
Users & Groups:
root@AnsiPress:~# id www-data
uid=33(www-data) gid=33(www-data) groups=33(www-data)
root@AnsiPress:~# id user1
uid=1001(user1) gid=1001(user1) groups=1001(user1)
root@AnsiPress:~# id user2
uid=1002(user2) gid=1002(user2) groups=1002(user2)
Permissions
root@AnsiPress:~# ls -lah /home/
drwxr-xr-x 3 user1 user1 4.0K May 8 09:34 user1
drwxr-xr-x 3 user2 user2 4.0K May 8 09:37 user2
ls -lah /home/user*/
drwxr-xr-x 3 user1 user1 4.0K May 8 09:34 vhosts
drwxr-xr-x 3 user2 user2 4.0K May 8 09:37 vhosts
root@AnsiPress:~# ls -lah /home/user*/vhosts/*
/home/user1/vhosts/user1.com:
total 28K
drwxr-xr-x 6 user1 user1 4.0K May 8 09:36 .
drwxr-xr-x 3 user1 user1 4.0K May 8 09:34 ..
drwxr-xr-x 2 user1 user1 4.0K May 8 09:34 conf
drwxr-xr-x 5 user1 user1 4.0K May 8 09:36 htdocs
drwxr-xr-x 2 user1 user1 4.0K May 8 09:34 logs
drwxr-xr-x 2 user1 user1 4.0K May 8 09:34 ssl
-rw-r--r-- 1 user1 user1 3.0K May 8 09:36 wp-config.php
/home/user2/vhosts/user2.com:
total 28K
drwxr-xr-x 6 user2 user2 4.0K May 8 09:38 .
drwxr-xr-x 3 user2 user2 4.0K May 8 09:37 ..
drwxr-xr-x 2 user2 user2 4.0K May 8 09:37 conf
drwxr-xr-x 5 user2 user2 4.0K May 8 09:38 htdocs
drwxr-xr-x 2 user2 user2 4.0K May 8 09:37 logs
drwxr-xr-x 2 user2 user2 4.0K May 8 09:37 ssl
-rw-r--r-- 1 user2 user2 3.0K May 8 09:38 wp-config.php
PHP POOL
/etc/php/7.1/fpm/pool.d/user1.conf
user = user1
group = user1
listen = 127.0.0.1:9011;
/etc/php/7.1/fpm/pool.d/user2.conf
user = user2
group = user2
listen = 127.0.0.1:9012;
Test read.php
root@AnsiPress:~# cat /home/user1/vhosts/user1.com/htdocs/read.php
<?php
echo file_get_contents('/home/user2/vhosts/user2.com/wp-config.php');
?>

@ingobaab I'd created read.php file under user1 and still its read user2 wp-config.php files. Let me correct If I'd miss anything here.
v4 already has php process isolation and webroot isolation.
Only thing remaining is giving FTP access per site. I am closing this issue as we FTP related discussion will be separate.