There a lot of ways to use PHP with Apache, with the most popular probably being mod_php due to its ease of use. However there are many problems with mod_php both security and performance-wise and other solutions have been created over time to address those problems. PHP-FPM (PHP FastCGI Process Manager) is one of the newer PHP SAPIs and generally is (from our initial testing) an excellent combination of the performance of FastCGI and security benefits of suPHP. Unfortunately the setup can be somewhat confusing so I’ll walk through the process on 64bit CentOS 5.
The first step is install mod_fastcgi (replace lib64 with lib if installing on a 32 bit system):
curl -s http://fastcgi.com/dist/mod_fastcgi-2.4.6.tar.gz | \<br /> tar xzf - && cd mod_fastcgi-2.4.6 && \<br /> make -f Makefile.AP2 top_dir=/usr/lib64/httpd && \<br /> cp .libs/mod_fastcgi.so /usr/lib64/httpd/modules/ && \<br /> cat > /etc/httpd/conf.d/mod_fastcgi.conf <<EOF<br /> LoadModule fastcgi_module /usr/lib64/httpd/modules/mod_fastcgi.so</p> <p><IfModule mod_fastcgi.c><br /> AddType application/x-httpd-php .php<br /> Action application/x-httpd-php /php.fcgi<br /> </IfModule><br /> EOF
Then for each user you want to have access to PHP-FPM add
FastCGIExternalServer /dev/shm/$USERNAME-php.fcgi -socket /dev/shm/$USERNAME-php.sock -flush (with
$USERNAME replaced with their username of course) to
/etc/httpd/conf.d/~mod_fastcgi.conf. Now, for each virtualhost you need to add a section like this:
<IfModule mod_fastcgi.c><br /> Alias /php.fcgi /dev/shm/$USERNAME-php.fcgi<br /> </IfModule>
$USERNAME replaced with the user that “owns” that virtualhost.
Now you’ll need to install PHP-FPM either by compiling it or via yum. We use our own PHP RPMs but the IUS repo has PHP5.3 RPMs with PHP-FPM so those could work. Once PHP-FPM is installed you’ll want to make sure
/etc/php-fpm.d/*.conf. Then for each user that got a
FastCGIExternalServer line, create a configuration file
[$USERNAME]<br /> listen = /dev/shm/$USERNAME-php.sock<br /> listen.owner = $USERNAME<br /> listen.group = apache<br /> listen.mode = 0660<br /> user = $USERNAME<br /> pm = ondemand<br /> pm.max_children = (2 x the number of processors in the server)<br /> pm.max_requests = 1024
After that, just start PHP-FPM and restart Apache with:
/etc/init.d/php-fpm start && \<br /> httpd -S && \<br /> /etc/init.d/httpd restart
and you should be all set!