Compiling PHP 5.3.0 with FPM
Posted: July 21, 2009 | By: TJ | In Technology | No comments yet
PHP-FPM (PHP FastCGI Process Management) is a patch for PHP to improve PHP’s FastCGI capabilities and administration. Prior to FPM, I was using the spawn-fcgi library from Lighttpd to manage PHP processes for Nginx. Although this works as it should, I was curious to try FPM given some of the configuration options. Some of the key features over using FastCGI are:
1. Process Management. Using PHP-FPM provides the ability to gracefully stop and start PHP workers without losing any queries. You also have a log and pid file as well.
2. Restrict IP addresses from which requests can come from.
3. Start the workers with different uid/gid/chroot/environment and different php.ini option. You do not need a safe mode.
4. Just like MySQL, PHP-FPM provides the ability to track the slow execution of scripts and record them in a log file along with the backtrace.
The most recent patch provided is for PHP 5.3.0. The following will outline how to install and patch PHP 5.3.0 with FPM:
$ cd /usr/local/src/ $ wget http://us.php.net/get/php-5.3.0.tar.bz2/from/this/mirror $ tar -jxvpf php-5.3.0.tar.bz2 $ wget http://php-fpm.org/downloads/php-5.3.0-fpm-0.5.12.diff.gz $ gzip -cd php-5.3.0-fpm-0.5.12.diff.gz | patch -d php-5.3.0 -p1 $ cd php-5.3.0
Now, this part is really up to you. I’ve set this up on a development VM with VirtualBox so if you want to compile PHP with different extensions, check php.net for availability:
$ ./configure --enable-fastcgi --enable-fpm --with-mcrypt --with-zlib --enable-mbstring --with-openssl --with-mysql --with-mysql-sock --with-curl --with-gd --enable-gd-native-ttf --without-sqlite --disable-pdo --disable-reflection
Now, make and install:
$ make all install $ strip /usr/local/bin/php-cgi
Edit the php-fpm.conf so that PHP runs as www-data instead of nobody. You’ll need to uncomment lines 63 and 66 as well:
$ vim /usr/local/etc/php-fpm.conf :63 www-data :66 www-data
To create the init script, we’ll symlink the one provided and update the rc.d:
$ cd /etc/init.d/ $ ln -s /usr/local/sbin/php-fpm php-fpm $ /usr/sbin/update-rc.d -f php-fpm defaults
Start it up:
$ /etc/init.d/php-fpm start





