Running PHP through PHP-FPM with Apache 2.2

Running PHP through PHP-FPM is pretty easy in Apache 2.4 (or Nginx for that matter) with ProxyPass, however Apache 2.2 has no built-in convenient way to do it.

There’s a number of solutions that exist to accomplish this, but it seems that the ambiguously named mod_fastcgi.c is the least bad. One of the biggest issues I ran into while setting it up, was allowing for multiple fpm pools for the different virtual hosts, and the specific set of configurations that I’ve figured out allowed me to do this quite easily.

There’s are number of intricate things which must be done to get it working correctly, and while I hope that I nor anyone else ever has to do this again – let’s face the bleak reality, it’s not entirely unlikely that we will… so here’s how we get it going;

  1. Download and compile (yep) the apache module from their website. I’ll spare the installation instructions since they are described in detail in the module files. Ensure you have the httpd-devel or equivalent package installed before commencing.
  2. In your httpd.conf, surround the configuration include directives with the following code:

  3. Inside your virtual host definition file, but before and outside of the definition itself, define the fpm server like so:

  4. Then define it’s use inside the virtual host definition:

Hopefully those configurations are all that you need. As always, different pools will require different names (in this case mine is called prod) and ports. Also note the directories, and ensure they exist – particularly /var/lib/php-fpm and /var/lib/httpd/fasicgi .