I have managed to get FastCGI working with Apache 2.4 on Ubuntu 16.04 by adapting instructions from this askubuntu thread, this HowtoForge document, and this Digital Ocean tutorial.

All those sources say to create /etc/apache2/conf-available/php7.0-fpm.conf and tell you what to put in it. But after installing php-fpm, I already have that file, with the following contents:

# Redirect to local php-fpm if mod_php is not available
<IfModule !mod_php7.c>
    # Enable http authorization headers
    SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1

    <FilesMatch ".+\.ph(p[3457]?|t|tml)$">
    SetHandler "proxy:unix:/run/php/php7.0-fpm.sock|fcgi://localhost"
    <FilesMatch ".+\.phps$">
        # Deny access to raw php sources by default
        # To re-enable it's recommended to enable access to the files
        # only in specific virtual host or directory
        Require all denied
    # Deny access to files without filename (e.g. '.php')
    <FilesMatch "^\.ph(p[3457]?|t|tml|ps)$">
        Require all denied

So I have instead created my own conf and put the code from the instructions in it and enabled it.

What is the existing php7.0-fpm.conf for? If I enable it in addition to my conf, my websites stop working. I'm worried that I'm no doing this the way it's intended to be done and could have problems in the future. It's really difficult to find good, current documentation on this.

For reference, here is my entire procedure:

sudo apt install libapache2-mod-fastcgi php-fpm
sudo a2dismod php7.0 mpm_prefork
sudo a2enmod actions fastcgi alias mpm_worker
sudoedit /etc/apache2/conf-available/custom-fpm.conf

Contents of /etc/apache2/conf-available/custom-fpm.conf:

<IfModule mod_fastcgi.c>
    AddHandler php7-fcgi .php
    Action php7-fcgi /php7-fcgi virtual
    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-header
    <Directory /usr/lib/cgi-bin>
            Require all granted

Commands continued:

sudo a2enconf custom-fpm
sudo systemctl restart apache2 && sudo systemctl restart php7.0-fpm

Thanks in advance for your help.

1 Answer 1


I hit the same confusion, I feel your pain. After a lot of reading it's become clear to me that most articles are out of date and referring to previous methods (or sometimes combinations).

Using PHP-FPM with Ubuntu 16.04's built-in config, you only need to do this:

sudo a2enconf php7.0-fpm
sudo a2enmod proxy proxy_fcgi

I did most of what you did, then removed it all, when that custom config didn't make sense.

What is the existing php7.0-fpm.conf for?

The config you found installed by the package is for using mod_proxy_fcgi. It binds .php files via mod_proxy_fcgi to PHP FPM, using mod_proxy, via a Unix Domain Socket. As far I know this is the most up-to-date "recipe" (of the six now available!)

You do not need to install libapache2-mod-fastcgi that's a different, older method. You do not need to write that configuration - that's for using mod_fastcgi directly. You do not need to install actions fastcgi alias as they are to configure mod_fastcgi.

I do find it odd that none of the articles - even those for Ubuntu 16 - mention the new recipe is all set up for you!

This comment clarified the history for me:

The preferred method is now fastcgi, using either of those recipes:

(mod_fastcgi, httpd 2.2) http://wiki.apache.org/httpd/php-fastcgi

(mod_fcgid, httpd 2.2) http://wiki.apache.org/httpd/php-fcgid

(mod_proxy_fcgi, httpd 2.4) http://wiki.apache.org/httpd/PHP-FPM

http://php.net/manual/en/install.unix.debian.php#112544 (2013)

Furthermore this article from Apache, details the three sub-options for configuring mod_proxy_fcgi to connect to FPM, using either ProxyPassMatch or SetHandler + UDS. Note that UDS is since Apache 2.4.10 per https://httpd.apache.org/docs/2.4/mod/mod_proxy_fcgi.html so one needs trusty-backports or newer.


So I've come to visualise there are now six ways to configure it:

In roughly historical order:

  1. Apache PHP module: mod_php (the old way)

  2. Via FastCGI - using Handler/Action/Alias/FastCgiExternalServer config

    a. mod_fastcgi

    b. mod_fcgid

  3. Using PHP-FPM via mod_proxy_fcgi, configured via either:

    a. TCP socket (IP and port) ProxyPassMatch ... fcgi://

    b. Unix domain socket (UDS) ProxyPassMatch … unix:/path/to/socket

    c. (UDS) via SetHandler "proxy:unix: OR SetHandler "proxy:fcgi:

Disclaimer: this is all new to me, so I've probably still got five things wrong and ten things to learn.

  • @scipilot also get really confused - still. Even this was 5 years ago. I did how you said but still get "Apache 2.0 Handler " as a Server API
    – Isengo
    Sep 26, 2017 at 14:05
  • @Isengo I don't quite understand your question. Perhaps if you write it up as a new separate question with more details, myself and others could help.
    – scipilot
    Sep 29, 2017 at 23:19
  • Note that proxy_fcgi is not RFC 3875 compliant bz.apache.org/bugzilla/… and for example, local internal redirections one could do with something like header("Location: /triop.gif", true, 200); exit(); using php-fpm + mod_FastCGI will not work...
    – 2072
    Aug 5, 2018 at 2:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.