Install PHP-FPM on Ubuntu and Debian

→ Are you a new visitor? Please visit the page guidance for new visitors ←

Install PHP-FPM on Ubuntu and Debian

What is PHP-FPM? That’s probably some of you are thinking, or maybe someone of you found this page by looking how to install it, anyway, FPM stands  for Fastcgi Process Manager. This is a much better alternative to PHP Fastcgi, can be used on any sites, but mostly used with busier sites where owners want to make best use of their server resources. It will speed your website as PHP-FPM is faster than the legacy PHP Fastcgi while keeping resources as low as possible and not only that, you have a lot of control over the PHP processes compared to normal PHP Fastcgi module. Anyway, in this tutorial I’m going to show you how to install PHP-FPM on Ubuntu and debian operating systems.

Preparing repositories

With PHP-FPM you are required to have some repositories, first for PHP extensions and then also for FPM. I currently use the Doteb repository for Debian and Ubuntu, I’m going to use them this time also, so add the below lines to your /etc/apt/sources.list

Don’t forget the Doteb key for using this repository:

You will also need one other repository for the apache fastcgi module, unfortunately this is in the non-free archive area. Add the line below to your /etc/apt/sources.list

Next don’t forget to update the package list, it is necessary on Debian / Ubuntu:

Install php, php extensions and FPM

Next step here is to install php and all php extensions needed for our website scripts. Use  below command to install these:

Once we finished to install PHP and all the PHP extensions needed, we can start installing PHP-FPM

Once we’ve completed this step, we proceed with installing the FastCGI module for apache2.

Install mod_fastcgi on Ubuntu and debian

For this you only need to run at this point the command below:

The apache module will be installed and enabled and you should be ready to go. I’ve added the actions module to be enabled as we will need this at the end.

Configuring PHP-FPM with mod_fastcgi

This step is the tricky part, in all my setups I’ve used I’ve set PHP-FPM to listen on a specific port on all my IP address, well you can specify what ever IP address you wish or if you want it to listen on a unix socket, but that’s more or less of a preference. In my case I’ll go with it listening on a specific port. Open the file:

/etc/php5/fpm/pool.d/www.conf

This is the default pool for our FPM processes, keep in mind that FPM works with pools, you can create a number of pools for different websites, while having different settings and all that. Well you would change the listen line to the default port 9000 like below:

Once you’ve completed this, restart the php5-fpm service:

The last part now is to have mod_fastcgi connect to our php5-fpm service, we do this by creating the file:

/etc/apache2/conf.d/mod_fastcgi.conf

and adding the contents below:

Save the file and restart apache:

The end result will be spotted if you create a simple phpinfo() page, see bellow image:

phpinfo php5-fpm

phpinfo php5-fpm

That’s it for today, thanks for reading and will see you again in our next tutorial!

Request an article ←