All Linux HowTo's

Configure Apache2 with PHP-FPM on CentOS

Share This:

This document explains how to convert an Apache2+php server to Apache2+php-fpm. We’re staring from a system with Apache already installed and PHP working.

Install the additional software:

rpm -ivh rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
yum install mod_fastcgi php-fpm

This directory needs to exist:

mkdir /usr/lib/cgi-bin

Configure Apache/Httpd.

Here is a sample virtual server within the “/etc/httpd/conf/httpd.conf” file:

<VirtualHost *:80>
 #FastCGIExternalServer /var/www/html/cgi-bin/php5.fcgi -host
 ServerAdmin support@agix.local
 DocumentRoot /var/www/html/wordpress
 ServerName example.agix.local
 ErrorLog logs/wordpress-error_log
 CustomLog logs/wordpress-access_log common

Here is a sample “/etc/httpd/conf.d/php-fpm.conf” file:

Action fcgi-php-fpm /fcgi-php-fpm virtual
Alias /fcgi-php-fpm /fcgi-php-fpm
FastCgiExternalServer /fcgi-php-fpm -socket /var/run/php-fpm/web.socket -pass-header Authorization -idle-timeout 180

Here is a sample “/etc/httpd/conf.d/fastcgi.conf ” file:

User apache
Group apache

LoadModule fastcgi_module modules/
FastCgiIpcDir /var/run/mod_fastcgi
FastCgiWrapper Off
FastCgiConfig -idle-timeout 20 -maxClassProcesses 1

<IfModule mod_fastcgi.c>
DirectoryIndex index.html index.shtml index.cgi index.php
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 -host -pass-header Authorization

Here is a sample “/etc/httpd/conf.d/php.conf” file:

<IfModule prefork.c>
<IfModule worker.c>
DirectoryIndex index.php

You should be able to test and confirm it’s working. Restart services first though.

service php-fpm restart
service httpd restart
chkconfig httpd on
chkconfig php-fpm on

Similar Posts:

Leave a Reply

Your email address will not be published. Required fields are marked *