Apache2 with PHP-FPM

PHP-FPM is another way to use PHP with Apache2, we forget the libmod-apache2-phpX. PHP-FPM is a variant of FAST-CGI.

PHP-FPM has the advantage of no longer being embedded in Apache. So PHP is used / called when needed.(When an image is requested PHP does not need to be loaded).

PHP-FPM installs PHP as a service and it is launched in another process than the web server (Security gain).

In terms of performance, PHP-FPM has the best result when scaling the Web server.

One of the big advantages also of using PHP-FPM is to be able to coexist several versions on the Web server and pass a site from one version to another very easily.

Install PHP-FPM

Enter the following command :

apt install php7.x-fpm

Configuration

1. Go to the / var / run / php folder and display the content, it must be a phpy.x-fpm.sock file.

php-fpm pid

If you install multiple versions of PHP, there will be one .sock / .pid file per installed version.

2. Enable Apache proxy_fgci mod

a2enmod proxy_fcgi

3. Restart the Apache 2 service.

service apache2 restart

4. Edit the apache or vhost configuration file by adding the following lines before :

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

Adapt the version of PHP according to your configuration.

5. Reload the Apache configuration:

service apache2 reload

6. Validate the use of PHP-FPM using the phpinfo(); function. You have to look at the result of Server API.

phpinfo

Conclusion

By using PHP-FPM, it is easy to use multiple versions of PHP on the same web server and choose the version depending on the vhost.

The advantage also, if you change the php.ini file, it is no longer necessary to restart the apache service, you must restart the php-fpm service.

In terms of performance, I find them better, generating page time reduced by 10 to 20% on a GLPI server with 2K inventory item.

Personally I prefer this configuration which is close to IIS and allows the use of several PHP on the same WEB server.




Leave a Comment