Blog

Configuring Apache with PHP-FPM on Ubuntu

/ infrastructure, php, fpm, ubuntu

As I already mentioned in the article Configuring Apache with PHP-FPM in CentOS/RHEL 7, PHP-FPM is a much more efficient to handle large volumes of queries. In this article we will see how to configure it in Ubuntu.

In this article we will assume that we already have apache2 installed on our system. First we will install the php7.2-fpm package:

sudo apt install php7.2 php7.2-{fpm,common}

Now we must install the FastCGI module of apache2, for them we will execute the following commands:

wget http://mirrors.kernel.org/ubuntu/pool/multiverse/liba/libapache-mod-fastcgi/libapache2-mod-fastcgi_2.4.7\~0910052141-1.2_amd64.deb
sudo dpkg -i libapache2-mod-fastcgi_2.4.7~0910052141-1.2_amd64.deb

Once installed we must activate several necessary apache2 modules:

sudo a2enmod actions fastcgi alias proxy_fcgi

If the apache2 php module is activated, we must deactivate it so that fpm works correctly.

sudo a2dismod php7.2

It's time to edit the file /etc/apache2/sites-available/000-default.conf to add the FPM handler configuration:

sudo vim /etc/apache2/sites-available/000-default.conf

We will add the following lines:

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

Alternatively we can directly activate the php-fpm configuration with the command:

sudo a2enconf php7.2-fpm

Finally we restart the apache2 server and the fpm service:

sudo systemctl restart {apache2,php7.2-fpm}.service

Additionally, we can make changes to the process pool configuration in the file /etc/php/7.2/fpm/php-fpm.conf.

Next Post Previous Post