Manual Apache modifications to use mpm-event, php-fpm, etc.

1 post / 0 new
#1 Thu, 11/03/2016 - 17:45
Jason at eROI

Manual Apache modifications to use mpm-event, php-fpm, etc.

Hello,
I have been playing with apache 2.4 on ubuntu 16.04 LTS server. My goal here is to show the minimum settings required to get php-fpm running in hopes it can be implemented with virtualmin soon. I would take a crack at it myself but I am really unfamiliar with the perl code of virtualmin...

There is a veritable tonne of (conflicting) information about configuring apache, php-fpm, and various combinations of fcgi, fastcgi, etc.

The method I found only requires mod_proxy and mod_proxy_fcgi.

My reference is https://wiki.apache.org/httpd/PHP-FPM. I also asked a few questions on the apache-users maillists. Assumptions ubuntu 16.04 LTS server has the following - apache 2.4.18 - php 7.0 - no virtualmin (aka plain linux server...)

using 000-default.conf that came with apache
test.php located in /var/www/html:

<?php
phpinfo();
?>
  1. enable mpm-worker or mpm-event. don't use mpm-prefork.
  2. install php-mpm: "apt-get install php7.0-fpm". This will run a daemon process whose configuration is in /etc/php/7.0/fpm/php-fpm.conf.
  3. Alter "Listen" line in /etc/php/7.0/fpm/pool.d/www.conf to "Listen=127.0.0.1:9000"
  4. Restart php-mpm "service php7.0-fpm restart"
  5. install mod_proxy, mod_proxy_fcgi, enable by running "a2enmod proxy proxy_fcgi"
  6. in the relevant virtualhost section enter the line "ProxyPassMatch ^/(..php(/.)?)$ "fcgi://127.0.0.1:9000/var/www/html/$1" enablereuse=on"
  7. restart apache "service apache2 restart"
  8. navigate to test.php

notes:
- The ProxyPassMatch part appends the php file path from the url to /var/www/html/.
- The port listened to by php-fpm could be a unix socket located in the user/site's home directory

php-fpm information: php-fpm is part of php now. It's no longer a separate effort. it supports the concepts of "pools", each pool can have a different uid/gid, and even bind to a different port/socket. The ProxyPassMatch directive can be declared at the vhost level, thus code could be run in user sandboxes. This site shows some of the weaknesses of php-fpm and ways to leverage around it.

What do you all think?

--jason