Help with PHP-FPM on Apache

I am testing Apache2 + PHP-FPM as well right now.

It took me some time to see through the different implementation methods, using mod-fcgid or proxy_fcgi.

What I finally did:

apt install php-fpm
a2dismod php7.0 mpm_prefork
a2enmod mpm_event proxy_fcgi
apt purge libapache2-mod-php7.0

And then I added the following to /etc/apache2/apache2.conf:

<FilesMatch \.php$>
        SetHandler "proxy:unix:/var/run/php/php7.0-fpm.sock|fcgi://localhost/"
</FilesMatch>

Everything seems fine, phpinfo() shows Server API FPM/FastCGI and Nextcloud is running.

Some guides also suggest to add

<Proxy "fcgi://localhost/">
</Proxy>

But it seems not needed and I cannot see any difference after adding it, thus left it out.

My question is now that as Apache still spawns child processes, even that php-fpm definitely is used.
I was thinking, that as just PHP files are handled by php-fpm, that static html files are still handled by Apache and it’s child processes, thus this is expected?

On the other hand, Nginx and Lighttpd do not need own child processes, thus html files seem to be handled by php-fpm as well or by their webserver master process?

The amount of Apache child processes btw. seem to be configurable via /etc/apache2/mods-available/mpm_event.conf.

1 Like