How to configure Apache to use mod_fastcgi and php-fpm

apache-2.2mod-fastcgiphp-fpm

Now I am running Apache to serve php files using mod_php. Will I get a performance enhancement while running PHP in fastcgi mode? There are two virtualhosts on this server for now. I followed this tutorial that I made by referring three different tutorials:
https://docs.google.com/document/d/1Pk9tZ8Vg1IbrvVUVPusnCYnRUZCOLRvdXkDYEqm_-4Y/edit?usp=sharing

But after restarting apache, I got an error. What could be the issue?

File not found: /php5-fcgi/index.html

The server I am using is a CentOS server with the following specs:

CentOS release 6.6 (Final)
Pentium(R) Dual-Core  CPU      E5200  @ 2.50GHz
MemTotal:        1910040 kB
MemFree:          586200 kB
Buffers:          259076 kB
Cached:           646432 kB
250 GB HDD

Apache/2.2.15
PHP 5.4.37
mysqladmin  Ver 8.42 Distrib 5.5.41, for Linux on x86_64

Best Answer

You're missing some of the required parameters from your apache configuration. This is the config that works for me:

<IfModule mod_fastcgi.c>
  User  apache
  Group apache
  AddHandler fastcgi-script .fcgi

  FastCgiConfig -idle-timeout 20 -maxClassProcesses 1
  FastCgiIpcDir /var/run/mod_fastcgi

  Alias  /php.fcgi /var/www/cgi-bin/php.fcgi
  AddType application/x-httpd-fastphp .php
  Action  application/x-httpd-fastphp /php.fcgi

  FastCGIExternalServer /var/www/cgi-bin/php.fcgi -socket /var/run/php-fpm/pool-www.sock -idle-timeout 35

  <Directory "/var/www/cgi-bin">
    Options +Indexes FollowSymLinks +ExecCGI
    AllowOverride AuthConfig FileInfo
    Order allow,deny
    Allow from all
    <Files "php.fcgi">
      Options +Indexes FollowSymLinks +ExecCGI
      Order deny,allow
      Allow from All
    </Files>
  </Directory>

</IfModule>

Put the contents into /etc/httpd/conf.d/fastcgi.conf, and in your vhost files just use DirectoryIndex.

Offcourse, couple it with appropriate:

listen = /var/run/php-fpm/pool-www.sock

In /etc/php-fpm.d/your_custom.conf