How To Enable PHP-FPM on Ubuntu 14.04

By | June 27, 2017

We can use php-fpm on Apache to boost performance. Please follow this step to enable.
Install and activate apache2-mpm-event by running the following commands:

sudo apt-get update
sudo apt-get install apache2-mpm-event

To use PHP5-FPM with Apache, we need to install libapache2-mod-fastcgi module. The libapache2-mod-fastcgi module is not available in the Ubuntu package. Therefore, we need to update the apt sources. Follow these steps.

sudo nano /etc/apt/sources.list

Add the following lines at the end of the file:

deb http://us.archive.ubuntu.com/ubuntu/ trusty multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ trusty multiverse
deb http://us.archive.ubuntu.com/ubuntu/ trusty-updates multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ trusty-updates multiverse

Install libapache2-mod-fastcgi:

sudo apt-get update
sudo apt-get install libapache2-mod-fastcgi

Install PHP5-FPM with the following command:

sudo apt-get install php5-fpm

Create the PHP5-FPM configuration file for Apache:
sudo nano /etc/apache2/conf-available/php5-fpm.conf

then add the following lines:
<IfModule mod_fastcgi.c>
AddHandler php5-fcgi .php
Action php5-fcgi /php5-fcgi
Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi
FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -socket /var/run/php5-fpm.sock -pass-header Authorization
<Directory /usr/lib/cgi-bin>
Require all granted
</Directory>
</IfModule>

Enable the new modules and configuration for Apache:

sudo a2enmod actions fastcgi alias
sudo a2enconf php5-fpm

Also enable mod_proxy and mod_proxy_fcgi apache modules

Thank you