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:


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:


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!

  • Server API still remain Apache 2.0 Handler, what’s wrong?

    • A stupid solution would be to restart apache? But I don’t think that’s the issue…

      Wrong turn at or after some point … can’t really know what’s wrong without really seeing the configuration there.

      What I can think of, disable / uninstall the php5 module and carefully check apache to use only fastcgi with php-fpm

      • Hallo, thanks for replying!
        We like to run both parallel for testing, is this possible? Because we use currently many php_value in htaccess file and so we must migrate this all to a user.ini

        • It should be possible, but you need to enable the modules per vhost instead so that you don’t have conflicts with configs. This is not the purpose of this tutorial, the way you do it is pretty much the same, just try to set the fastcgi params in your vhost configuration instead.

          And also do not forget to enable mod_fastcgi!

  • Amelie Perrin

    Hello thanks for your howto.

    I have follow all step but in my phpinfo i still have:
    Server API: CGI/FastCGI
    Configuration File (php.ini) Path: /etc/php5/cgi

    I don’t see php-fpm any where. I have a server with debian 7 and i also install virtualmin.

    So I have in my apache2: sites-available

    Can you help me to see where come the problem.
    Excuse my bad english.

    • It looks like you run this with cgi or fcgi.

      You need to make sure cgi / fcgi is disabled, then make sure in your /etc/apache2/conf.d/mod_fastcgi.conf file you have the correct directives.

      Make sure in the conf.d folder you do not have any other php directives for cgi / fcgi (eg. another php5*.conf file)

      Then you should get it working if you followed the tutorial.

Request an article ←