Running PHP-FPM with Apache2.4/mod_proxy_fcgi

Apache2.4 does not support mod_fastcgi, the alternate option is to run php-fpm with mod_proxy_fcgi.

On Ubuntu you need to enable mod_proxy and mod_proxy_fcgi.

a2enmod mod_proxy mod_proxy_fcgi

We can now configure apache to run php-fpm as below

 ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/var/www/html/$1

Here php-fpm is listening on port 9000, and it will run all file with extension .php in the DocumentRoot /var/www/html

We can also have different versions of PHP for sub-directories. For example

ProxyPassMatch ^/forum/(.*\.php)$ fcgi://127.0.0.1:9072/var/www/html/forum/$1
ProxyPassMatch ^/blog/(.*\.php)$ fcgi://127.0.0.1:9071/var/www/html/blog/$1

Above the forum sub-directory will be running with PHP 7.2 listening on port 9072 and the blog sub-directory will run PHP 7.1 listening on port 9071

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

Leave a comment

Your email address will not be published. Required fields are marked *