Apache 2.4 with php5-fpm

Posted April 24, 2014 133.4k views
I've spent so many hours trying to make the following setup: Apache v2.4 php-fpm to work, but without any success. I am using fully updated Ubuntu Server 14.04 TLS. Most of the tutorials online are for nginx with php-fpm or Apache 2.2, but I know things have changed.
  • For those trying to get PHP FPM to work with PHP 7.0, here’s what I had to do. I’m running a 512MB droplet with Apache 2.4.x and Ubuntu 14.04 LTS. Disabling mod_php and handing this work off to PHP FPM has made a HUGE improvement in my memory utilization and this is very important to me given I only have 512MB to work with! Prior to making the changes below, I was running >70% RAM usage (and often times >85%) and now I’m <50%.

    I opted to edit my global configuration file “/etc/apache2/conf-available/php7.0-fpm.conf” as I wanted PHP FPM enabled for all of my virtual hosts:

           <IfModule mod_fastcgi.c>
                    AddHandler php7-fcgi .php
                    Action php7-fcgi /php7-fcgi
                    Alias /php7-fcgi /usr/lib/cgi-bin/php7-fcgi
                    FastCgiExternalServer /usr/lib/cgi-bin/php7-fcgi -socket /var/run/php/php7.0-fpm.sock -pass-heade$
                    <Directory /usr/lib/cgi-bin>
                            Require all granted

    The <Directory …> bit was important was prior to this I was getting the following error:

    You don’t have permission to access /php7-fcgi/phpinfo.php on this server.

    I also had to create my php7.fcgi file:

    sudo touch /usr/lib/cgi-bin/php7.fcgi

    Then permission it so my web server can access it:

    sudo chown -R www-data:www /usr/lib/cgi-bin

    Couple of helpful resources I used: and

    Good luck!

  • Quick tip - you can avoid having to create a file in /usr/lib/cgi-bin/php7.fcgi by adding ‘virtual’ to the end of Action in the block above:

    Action php7-fcgi /php7-fcgi virtual

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
17 answers
Assuming that you're starting with a basic LAMP stack, first you need to install the needed packages:

sudo apt-get install libapache2-mod-fastcgi php5-fpm

Then create the file "/etc/apache2/conf-available/php5-fpm.conf" with the contents:

<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

Then enable the new mods and config:

a2enmod actions fastcgi alias
a2enconf php5-fpm
service apache2 reload

You should be up and running. To verify, create a file called "/var/www/html/info.php" with the contents:


Now you should be able to browse to

You should see a lot of information about your php set up including: "Server API FPM/FastCGI "
  • I have installed Apache2.4 with PHP5-FPM and libapache2-mod-fastcgi and configure it as per this above configuration.
    PHP5-Fpm is running but when i checked using phpinfo it’s not showing FPM.
    Current Status - >
    Apache 2.0 Handler
    PHP5-FPM is running
    tcp 0 0* LISTEN 16489/php-fpm.conf)

    Apache error logs
    FastCGI: process manager initialized (pid 16454)
    [mpmprefork:notice] AH00163: Apache/2.4.7 (Ubuntu) modfastcgi/mod_fastcgi-SNAP-0910052141 PHP/5.5.9-1ubuntu4.3 configured – resuming normal operations

    Please help me to configure it properly or let me know what i am missing.

  • Thanks a lot it worked…can you elaborate your answer in brief (this did that)…thanks again

I've managed to launch it. Actually I did the same by myself the last few times, but I always received the following error:
`client denied by server configuration: /usr/lib/cgi-bin/php5-fcgi`

The solution is to add this code to **/etc/apache2/conf-available/php5-fpm.conf**:
Require all granted



PS: I accidentally added **Ruby on Rails** tag to the question. It will be nice if a moderator can remove it, please.
Glad you got it working! I fixed up the tags.

For anyone else, here's Ivan's addition to php5-fpm.conf with the formatting fixed:

<Directory /usr/lib/cgi-bin>
Require all granted

You may also need to switch from the apache MPM non-threaded module mpm_prefork to a threaded one.

a2dismod mpm_prefork


a2enmod mpm_worker
a2enmod mpm_event

If it’s not installed:

apt-get install apache2-mpm-worker
apt-get install apache2-mpm-event

Hi, thanks for the info, does any one know why I get this info back from php_info()
Server API	Apache 2.0 Handler

PHP API	20121113

PHP Extension	20121212

Zend Extension	220121212
  • I think you need to ensure that mod_php is disabled first: $ sudo a2dismod php5 Module php5 disabled. To activate the new configuration, you need to run: service apache2 restart

Thanks for this.
Worked like a charm for my very first attempt.

In my case it worked when i moved the php5-fpm.conf to

Thank you very much. Worked like charm. Andrew and Richard, thank you both

another post about this - link to a unique site with awesome engineers

Previous 1 2 Next