News Archive
PhpRiot Newsletter
Your Email Address:

More information

PHP-FPM FastCGI Process Manager with Apache 2

Note: This article was originally published at Planet PHP on 14 March 2012.
Planet PHP

I've published some vanilla PHP 5.4.0 RPMs to make new feature testing easier.

Along with all the PHP 5.4 goodies, the php-fpm "FastCGI Process Manager" is available for the first time on Php-fpm is an alternative FastCGI interface to PHP with various extra features such as load dependent spawning of processes. (For other features, see Php-fpm has been getting more and more traction in the PHP community and the EXPERIMENTAL flag was removed in PHP 5.4. You might want to test it out.

To use php-fpm with the default Apache web server, first install Oracle Linux 5.8 (64bit) using Oracle's free, public yum repository

Install Apache, if not already installed:

yum install httpd

Download and install the PHP 5.4 RPMs from

rpm -i php54-common-5.4.0-1.el5.x86_64.rpm php54-fpm-5.4.0-1.el5.x86_64.rpm

Other extensions can also be installed, depending on the functionality you want to test.

Download and build FastCGI for Apache:

wget tar -zxf mod_fastcgi-current.tar.gz cd mod_fastcgi-2.4.6 cp Makefile.AP2 Makefile make top_dir=/usr/lib64/httpd

Install FastCGI as root:

make top_dir=/usr/lib64/httpd install

Edit /etc/httpd/conf/httpd.conf and comment out any existing references to PHP you might previously have added for testing:

# LoadModule php5_module modules/ # AddType application/x-httpd-php .php

Add the php-fpm configuration to httpd.conf:

LoadModule fastcgi_module modules/ FastCGIExternalServer /usr/sbin/php-fpm -host AddHandler php-fastcgi .php # # SetHandler php-fastcgi-virt # Action php-fastcgi-virt /usr/sbin/php-fpm.fcgi virtual #Action php-fastcgi /usr/sbin/php-fpm.fcgi ScriptAlias /usr/sbin/php-fpm.fcgi /usr/sbin/php-fpm Options ExecCGI FollowSymLinks SetHandler fastcgi-script Order allow,deny Allow from all

Start php-fpm and Apache:

service php-fpm start service httpd start

Test it out with your favorite script or create a file pi.php:

Save it in /var/www/html/pi.php or in $HOME/public_html/pi.php, if you have configured UserDir in httpd.conf.

In a browser load http://localhost/pi.php or http://localhost/~yourname/pi.php.

This will show the PHP configuration values.

To test php-fpm's built-in statistics, edit httpd.conf and uncomment the four lines of the LocationMatch section:

SetHandler php-fastcgi-virt Action php-fastcgi-virt /usr/sbin/php-fpm.fcgi virtual

Edit /etc/php-fpm.conf and uncomment the line:

pm.status_path = /status

Restart php-fpm and Apache:

service php-fpm restart service httpd restart

Run some load on the system:

ab -c 10 -t 60 http://localhost/pi.php

Now http://localhost/status gives you the status of the server:

pool: www process manager: dynamic start time: 13/Mar/2012:14:25:53 -0700 start since: 26 accepted conn: 50001 listen queue: 0 max listen queue: 6 listen queue len: 128 idle processes: 2 active processes: 1 total processes: 3 max active processes: 5 max children reached: 1

The php-fpm.conf file documents other output formats for the statistics. It also shows the extensive functionality available with php-fpm.

Documentation on php-fpm is not ideal, but you can see some at The site has more, including a forum and wiki

Truncated by Planet PHP, read more at the original (another 633 bytes)