Running on PHP-FPM

Have used FastCGI Process Manager (FPM) in other projects before. It really makes a whole lot of difference in page loading time. I don’t know why this has not become the default since PHP is literally everywhere and conventional PHP implementations are slow-ish. Also, it is not that complicated to set up. Of course, I am assuming you have a normal one like I do.

WordPress works with php-fpm right off the bat when I checked. Since I have not done heavy customizations that prevents this from working without lots of tweaking, then I should be good to go.

Note: I am using Ubuntu. While I can find my way on CentOS/Red Hat for example, the commands will be different, as well as the locations of packages and files.

Commands will be prefixed with a :~$ to be more readable and obvious. But do not include it when typing the same commands in your terminal. e.g. :~$ sudo ls -la should just be sudo ls -la when you copy/type it in.

Install the FPM packages

:-$ sudo apt install libapache2-mod-fastcgi php7.X-fpm

PHP-FPM runs as a different service. I check this out with the command – :-$ sudo service php7.X-fpm [action] – and start/restart it as necessary while I am doing additional configuration stuff. Where [action] can be start | stop | restart | status.

Note: Replace the X in php7.X-fpm with the version of PHP. Support for PHP-FPM went all the way back in version 5.3 as I recall.

Enable the Apache2 modules

Now that I have PHP-FPM installed, I proceed to enable the necessary Apache2 modules.

:-$ sudo a2enmod actions fastcgi

Module alias should be enabled already. Enable it if not.

The configuration to make this work in Apache2 is at the following server-wide location – /etc/apache2/conf-available/php7.X-fpm.conf – which the package install will have installed too. Recreate as necessary like this:

This can be site-specific too. The same above can be placed in the site definition or configuration. That one is found at – /etc/apach2/sites-available – choose the specific file. Place it within the Directory directive.

PHP-FPM configuration files

For PHP-FPM specific settings, it does not go in the normal php.ini. It has its own. These are located at – /etc/php/7.X/fpm – and the files of interest are – php-fpm.conf and pool.d/www.conf – while php.ini is also there specifically for FPM.

In php-fpm.conf options of interest are emergency_restart_threshold, emergency_restart_interval and process_control_timeout.

For pool.d/www.conf, I went with ondemand for how the process manager will control the number of child processes. This is good for lower traffic sites and/or when memory is small-ish. Adjust pm.max_children and pm.process_idle_timeout accordingly.

Start/restart the Apache2 service as necessary

:-$ sudo service apache2 restart

Similar Posts:

Notice: This article was published on May 19, 2020 and the content above may be out of date.