PHP FPM (FastCGI Process Manager) is a PHP process manager allowing to execute PHP code and is called via FastCGI by your webserver. It affords to your webserver to communicate with PHP and generally provides better performances. The purpose is to make PHP work in a separated way and to install the Apache FastCGI module in order to make Apache and PHP communicate.

Apache installation

At first, it is important to install Apache on the machine in question via the following command :

 apt-get install apache2

MySQL installation

Then, you need to install MySQL via the following command :

 apt-get install mysql-server

During the installation, you will be asked to choose a password root.

It is advised to carefully choose your password preferably alphanumeric and including special characters.

To continue with the installation, the following command must be executed :


Enter your password root when requested and confirm the four following questions with yes :

 Enter current password for root (enter for none):
    OK, successfully used password, moving on...

Remove anonymous users? [Y/n] y
 ... Success!

Disallow root login remotely? [Y/n] y
... Success!

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

PHP-FPM installation

Finally, you need to install PHP-FPM :

sudo apt-get install php5-fpm

So that Apache could join PHP-FPM, we install the Fast-CGI module :

sudo apt-get install libapache2-mod-fastcgi

PHP-FPM configuration

From then on, you have access to the PHP configuration :

ls -l /etc/php5/
total 4
drwxr-xr-x+ 3 root root   33 Jan 23 11:11 cli
drwxr-xr-x+ 4 root root   65 Jan 29 14:52 fpm
drwxr-xr-x+ 2 root root 4096 Jan 23 12:14 mods-available

Configuration folder for PHP from the command line.

Configuration folder for PHP-FPM.

Different modules folder installed for PHP, we will come back to it for the PHP module installation.

The configuration changes are operated by the file editing php.ini.


However, please notice that the default configuration is quite enough.
After any modification, you need to restart PHP-FPM :

sudo service php5-fpm restart

Apache configuration in FastCGI

PHP-FPM is currently operational but Apache now needs to know how to interpret the PHP code.
The fastcgi module has to change according to the following way :

vim /etc/apache2/mods-available/fastcgi.conf

# Configuration to add to the file fastcgi.conf
<IfPlug-in 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

Now, we activate the Actions module and restart Apache :

sudo a2enmod actions
sudo service apache2 restart

The PHP-FPM installation and configuration is complete, each PHP (.php) file will be processed by PHP-FPM.

PHP modules installation

It may happen that your system doest not have libraries/modules yet which you could need for your developer, yet you can still add some others such as GD for a PHP image processing :

### Display the librairies/modules already available and integrated to PHP 
php -m

### Complementary modules installation
sudo apt-get install php5-gd
sudo service apache2 restart

The modules installed are automatically activated and the respective configuration files are located in the /etc/php5/conf.d/ folder which returns to the /etc/php5/fpm/mods-available/ folder previously discussed.

 ls -l /etc/php5/fpm/conf.d/
total 0
lrwxrwxrwx 1 root root 32 Jan 23 11:11 05-opcache.ini -> ../../mods-available/opcache.ini
lrwxrwxrwx 1 root root 28 Jan 23 11:11 10-pdo.ini -> ../../mods-available/pdo.ini
lrwxrwxrwx 1 root root 29 Jan 23 11:42 20-curl.ini -> ../../mods-available/curl.ini
lrwxrwxrwx 1 root root 27 Jan 23 12:14 20-gd.ini -> ../../mods-available/gd.ini
lrwxrwxrwx 1 root root 29 Jan 23 11:11 20-json.ini -> ../../mods-available/json.ini
lrwxrwxrwx 1 root root 31 Jan 23 12:14 20-mcrypt.ini -> ../../mods-available/mcrypt.ini
lrwxrwxrwx 1 root root 31 Jan 23 12:14 20-mysqli.ini -> ../../mods-available/mysqli.ini
lrwxrwxrwx 1 root root 30 Jan 23 12:14 20-mysql.ini -> ../../mods-available/mysql.ini
lrwxrwxrwx 1 root root 34 Jan 23 12:14 20-pdo_mysql.ini -> ../../mods-available/pdo_mysql.ini
lrwxrwxrwx 1 root root 33 Jan 23 11:11 20-readline.ini -> ../../mods-available/readline.ini