(2011) Update: IUS renamed the packages to have a suffix of “u”. This was done to avoid conflicts with CentOS’s recently released PHP 5.3 packages. I prefer IUS since it maintains PHP’s version numbers and there’s some handy PECL extensions.
(2010-12-03) Update: EPEL updated nginx to 0.8.53 around early November. This post has been updated to use that package instead of IUS 0.7.
(2010-09-22) Update: IUS has fixed the repo: https://bugs.launchpad.net/ius/+bug/645409
(2010-09-22) Update: IUS updated the PEAR and APC packages and their repo appears to have come out of sync so you’ll experience errors until it’s fixed. Download the packages manually or use APC from repo 5 and FPM from repo 5.5 while making sure to “yum clean all” in between.
(2010-09-16) Update: I completely forgot that PHP-FPM also solves the APC cache issues that were present with php-fcgi where every php-fcgi process had it’s own APC cache. I include those steps.
IUS Community recently published PHP 5.3.3 PHP-FPM package but it isn’t in the default repo (which appears to be CentOS 5.4 and not 5.5). If you cannot install php53u-fpm then try changing the repo as detailed here:
https://bugs.launchpad.net/ius/+bug/591609
This post assumes that PHP is not already installed. If it is you’ll possibly get conflicts with some of the PHP packages when installing the IUS ones. IUS has a “yum replace” script but I have not used it. Otherwise, uninstall the old PHP RPMs before proceeding.
Install EPEL and IUS-Community repo packages:
#EPEL
wget http://dl.iuscommunity.org/pub/ius/stable/Redhat/5/x86_64/epel-release-1-1.ius.el5.noarch.rpm
#IUS Community
wget http://dl.iuscommunity.org/pub/ius/stable/Redhat/5/x86_64/ius-release-1.0-6.ius.el5.noarch.rpm
#Install repos
rpm -Uvh epel-release-1-1.ius.el5.noarch.rpm ius-release-1.0-6.ius.el5.noarch.rpm
You’ll then need to edit the ius repo to force it to CentOS 5.5 (check if this is still necessary by trying the next step first):
vi /etc/yum.repos.d/ius.repo
#Comment out this line:
mirrorlist=http://dmirr.iuscommunity.org/mirrorlist?repo=ius-el5&arch=$basearch
#Add this line:
baseurl=http://dl.iuscommunity.org/pub/ius/stable/Redhat/5.5/$basearch
Now you can easily install PHP 5.3.x, the new PHP-FPM package, and APC (it works correctly with PHP-FPM, yay) via:
#IUS PHP 5.3 packages are prefixed with "php53u" to avoid name clashes
yum install php53u-fpm php53u-pecl-apc
#Accept the dependencies
Next install nginx from IUS. Note that this is nginx 0.7.65 so it appears to have the usual backports from 0.8.
Next install nginx 0.8.53 from EPEL.
#Use EPEL nginx. See directly below if you want IUS 0.7
yum install nginx
#Note that IUS's nginx is suffixed with "07"
#yum install nginx07
Now you have the necessary packages installed. They don’t Just Work(TM) together out of the box so you’ll need to do some minor config changes.
For nginx edit /etc/nginx/nginx.conf and uncomment the entire block shown below to enable fastcgi forwarding for .php requests:
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
Within that same block also change:
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
To:
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
Now make a phpinfo to test:
#mmm phpinfo
echo "<?php phpinfo();" > /usr/share/nginx/html/phpinfo.php
#make sure APC is running. then copy the stats
cp /usr/share/doc/php53-pecl-apc-3.1.3p1/apc.php /usr/share/nginx/html/
Start it up:
chkconfig php-fpm on
chkconfig nginx on
service php-fpm start
service nginx start
Try it all out in a browser.
Note that this was the least number of steps to get this stack going. As usual be sure to check the other config settings for performance and security, like nginx’s number of connections and workers and changing php-fpm’s default user/group from the default of apache and chroot it to a jail.