Mittwoch, 19. April 2017

Using PHP-FPM + Apache on Ubuntu after upgrading to 17.04 (Zesty Zapus)

Up until Ubuntu 16.10 I used PHP-FPM on Apache via mod_fastcgi module. The setup was similar to what you can find in this tutorial: https://www.howtoforge.com/tutorial/apache-with-php-fpm-on-ubuntu-16-04/
With 17.04 the package mod_fastcgi was dropped from repository, as it seems to be unsupported since some time.

The way to go is switching to mod_proxy_fcgi, which seems to come preinstalled with the apache2 package and is just deactivated by default.

sudo a2enmod proxy_fcgi

I used PHP-FPM via socket and wanted to continue using it the same way, so I edited my site conf to add following lines within the VirtualHost configuration node:

<IfModule mod_proxy_fcgi.c>
    <Proxy "fcgi://localhost/" enablereuse=on max=10>
    </Proxy>
    <FilesMatch "\.php$">
        <If "-f %{REQUEST_FILENAME}">
            SetHandler "proxy:unix:/run/php/php7.0-fpm.sock|fcgi://localhost/"
        </If>
    </FilesMatch>
</IfModule> 

This was enough to make it run with the standard configuration. If you use a different socket for your vhost or do it via tcp with port, you would have to change the configuration accordingly. The official documentation of apache project for PHP-FPM lists the different configuration possibilities.