sysadmin: Apache, FastCGI and PHP-FPM working config

apache-php-fpm
I was looking for working config for the combination of apache mod_fastcgi and PHP-FPM and could not find any. I mean there were plenty of examples and discussions but none of them were operational. The closest was the article on server-world.info site.
Based on that information I was able to put together working configuration for multiple virtual hosts.

  • Initial assumption – we have Centos with installed stock httpd, mod_fastcgi (from rpmforge repository) and php54-fpm as part of IUS repository packaged php-5.4 modules
  • Apache configured as prefork, php-fpm configured with 3 process pools on TCP ports (while unix socket considered by many as fast way of communication with FastCGI server it is known with data loss under heavy load. So we will configure port 9000 – default, PHP process user/group apache/apache. 9001 – domainA, user/group userA/groupA correspondingly, 9002 – domainB, userB/groupB
  • default pool configuration

    The only 4 differences between this pool configuration and domainA and domainB pool configurations would be – pool name, port number, process user/group. Configure php-fpm pools for domainA and domainB with different pool names, port numbers and user/group accordingly.

  • Now, apache /etc/httpd/conf.d/fastcgi.conf

    There are 4 important lines in it – AddHandler, Action, ScriptAlias, FastCgiExternalServer that will appear again in virtual host configuration. Directory configured in ScriptAlias has to exist.
    Now you can restart php-fpm and httpd services for testing.

  • And the most interesting – virtual hosts domainA and domainB

    The important point is that you have to have distinctive handler for .php for each virtual host – that is how you can associate virtual host to specific pool on PHP-FPM. Once I’ve figured that out the rest was easy.

Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">