I am looking to run an number of Apache server which will host websites for multiple clients. I have installed the libapache2-mpm-itk module and have created unique users/groups for each clients set of files. And configured their corresponding vhost file to run the process with that user/group.
<IfModule mpm_itk_module> AssignUserId www-client www-client1 </IfModule>
This works fine until I try to use PHP sessions. In the vhost file I have also added a custom session save path.
php_admin_value session.save_path "/var/www/html/client1/_php/session"
A PHP script is able to generate session files in the directory with the following permissions but isn’t able to read them:
-rw------- www-client1 www-client1
A full example of my vhost is:
<VirtualHost *:443> ServerName client1.com ServerAlias client1.com www.client1.com DocumentRoot /var/www/html/client1/www ErrorLog /var/www/logs/client1/www-error.log CustomLog /var/www/logs/client1/www-access.log combined php_admin_value error_log "/var/www/logs/client1/www-error.php.log" <Directory /var/www/html/client1/www> Options None AllowOverride None Order Deny,Allow Allow from All </Directory> <IfModule mpm_itk_module> AssignUserId www-client1 www-client1 </IfModule> php_admin_value log_errors 1 php_admin_value open_basedir "/var/www/html/client1" php_admin_value upload_tmp_dir "/var/www/html/client1/_php/upload_tmp" php_admin_value session.save_path "/var/www/html/client1/_php/session" php_admin_value soap.wsdl_cache_dir "/var/www/html/client1/_php/soap_cache" SSLEngine On SSLCertificateFile /var/www/certs/client1/www.crt SSLCertificateKeyFile /var/www/certs/client/www.key </VirtualHost>
I’m running Apache 2.4.41,PHP 7.4.3 on Ubuntu 20.04 and there are no errors being outputted to any of my log files.
Any ideas/suggestions on this and further enhancements would be very much appreciated.
Advertisement
Answer
After a lot of Googling I have found a solution.
I also needed to ensure that php-fpm was installed and adding the following lines of configuration to the Apache VHost pointing to a unique PHP FPM socket per user fixed my issue.
<FilesMatch .php$> SetHandler "proxy:unix:/run/php/php-fpm-client1.sock|fcgi://localhost" </FilesMatch>
My PHP FPM configuration file looks like:
vi /etc/php/X/fpm/pool.d/client1.conf [client1] user = www-client1 group = www-client1 listen = /run/php/php-fpm-client1.sock listen.owner = www-client1 listen.group = www-client1 pm = dynamic pm.max_children = 5 pm.start_servers = 2 pm.min_spare_servers = 1 pm.max_spare_servers = 3 php_admin_value[log_errors] = 1 php_admin_value[error_log] = "/var/www/logs/client1/php-error.log" php_admin_value[open_basedir] = "/var/www/html/client1" php_admin_value[session.save_path] = "/var/www/html/client1/_php/session" bash /etc/init.d/php*-fpm restart
I also found that all php_admin_value
values defined in the VHost needed to be moved to the FPM pool.