(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.
Doesnt work.
Everything seems to go well (except that nginx and php-fpm do not restart on reboot) however the phpinfo returns a blank page.
OK sorry about that. I probably missed a step so let me re-run through it and check. Thanks for your input!
I clarified the nginx.conf steps a bit and added the chkconfig lines. I did the steps start to finish on a fresh CentOS 5.5 install and it works fine. Any errors in the logs?
Thank you for responding.
I have checked the logs and only inconsequential ‘favicon’ errors are listed in nginx log. The access log shows that it used get on ‘test.php’ but nothing else seems out of the ordinary.
A modification that I did make is that I was using 32 bit centos so I changed each file to its 32 bit counterpart. Today I will change the os on my vps to 64 bit and try again.
I will reply to let you know if this makes a difference.
Ok, I tried it with 64 bit centos and it worked.
Thanks
Whether it was a mistake by me or what I do not know, but it now works with the 32 bit version very well.
This is by far the easiest install of nginx and php available on the internet.
Please keep up the good work.
Rob Olmos, you rocks! I just created a SAN 2.0 VPS with bare Centos 5.5 + PHP 5.3.3 + PHP-FPM + Nginx 0.7.65.
I’m trying to do the same, but I can’t install APC…. I’ve tried both repo’s (5 & 5.5)
Error Downloading Packages:
php53-common-5.3.3-4.ius.el5.x86_64: failure: php53-common-5.3.3-4.ius.el5.x86_64.rpm from ius: [Errno 256] No more mirrors to try.
php53-cli-5.3.3-4.ius.el5.x86_64: failure: php53-cli-5.3.3-4.ius.el5.x86_64.rpm from ius: [Errno 256] No more mirrors to try.
php53-5.3.3-4.ius.el5.x86_64: failure: php53-5.3.3-4.ius.el5.x86_64.rpm from ius: [Errno 256] No more mirrors to try.
Looks like IUS has updated the APC and PEAR packages earlier today. I assume their repo data is in limbo which is causing this issue. Until they fix it, you should be able to download the packages manually using the yum repo URL.
figured it out:
apc was in repo 5
php-fpm was in repo 5.5
Also had to “yum clean all” after each change
also apc is now “php53-pecl-apc-3.1.4″
Thanks for the feedback. I created a bug report with IUS: https://bugs.launchpad.net/ius/+bug/645409
IUS has fixed this issue. Thanks again.
Installed without issues – however, having issues with installing php-mysql which i need. Any advice? Thanks…
Transaction Check Error:
file /etc/php.ini from install of php-common-5.1.6-27.el5.x86_64 conflicts with file from package php53-common-5.3.3-4.ius.el5.x86_64
You’ll have to uninstall the old PHP 5.1.6 RPMs before installing the new 5.3.3 ones. This install was done with a stock Rackspace Cloud Server install which doesn’t have PHP installed which I forgot to detail and will do so. Thanks for letting me know! There’s actually a “yum replace” script from IUS that will do so automatically but I haven’t used it.
How do I uninstall the old PHP RPM’s?
I started from a bare centos 5.5, there was no php installed prior to following your guide. It’s when i tried installing php-mysql that I got the error. Excuse my ignorance, this is not my area of expertise, any pointers much appreciated
php53-cli-5.3.3-4.ius.el5
php53-common-5.3.3-4.ius.el5
php53-pear-1.8.1-4.ius.el5
php53-fpm-5.3.3-4.ius.el5
php53-5.3.3-4.ius.el5
[root@myren ~]# yum install php-mysql
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* addons: mirrors.serveraxis.net
* base: centos.corenetworks.net
* epel: mirrors.tummy.com
* extras: yum.singlehop.com
* updates: mirror.ubiquityservers.com
Setting up Install Process
Resolving Dependencies
–> Running transaction check
—> Package php-mysql.x86_64 0:5.1.6-27.el5 set to be updated
–> Processing Dependency: php-common = 5.1.6-27.el5 for package: php-mysql
–> Processing Dependency: php-pdo for package: php-mysql
–> Running transaction check
—> Package php-common.x86_64 0:5.1.6-27.el5 set to be updated
—> Package php-pdo.x86_64 0:5.1.6-27.el5 set to be updated
–> Finished Dependency Resolution
Install 3 Package(s)
Upgrade 0 Package(s)
Total download size: 307 k
Is this ok [y/N]: y
Downloading Packages:
(1/3): php-pdo-5.1.6-27.el5.x86_64.rpm | 66 kB 00:00
(2/3): php-mysql-5.1.6-27.el5.x86_64.rpm | 89 kB 00:00
(3/3): php-common-5.1.6-27.el5.x86_64.rpm | 153 kB 00:00
———————————————————————————————————————————————————————————————————————————————————————————————————-
Total 425 kB/s | 307 kB 00:00
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Check Error:
file /etc/php.ini from install of php-common-5.1.6-27.el5.x86_64 conflicts with file from package php53-common-5.3.3-4.ius.el5.x86_64
No worries. I see the problem: The IUS packages are prefixed with “php53″ to avoid clashes. You’ll need to use “php53-mysql” instead of “php-mysql” for installing that package.
Oh man, that was way too easy, thanks!
Pingback: CentOS 5.5 PHP 5.3.3 PHP-FPM nginx (RPMs) | Rob Olmos - Phat Site Blog
When I follow the instructions,I am told that the packages do not exist
i got this error when running
ERROR with rpm_check_debug vs depsolve:
i’m using centos 5.5 32bit
Thanks a lot for the article, it saved me a lot of frustration with figuring out the new install, everything went very smoothly!
Your info is very useful for me ..
i think the compiling method still better (regarding performance issue) for me.. but .. the integration between apc and others modules will be easy with this method
Thank You
Same here: centos 5.5 x86_64 – phpinfo page is blank.
Installed:
php53-mysql-5.3.3-4.ius.el5
php53-fpm-5.3.3-4.ius.el5
php53-cli-5.3.3-4.ius.el5
php53-pecl-apc-3.1.4-1.ius.el5
php53-devel-5.3.3-4.ius.el5
php53-pear-1.8.1-5.ius.el5
php53-pdo-5.3.3-4.ius.el5
php53-5.3.3-4.ius.el5
php53-common-5.3.3-4.ius.el5
Nothing in log
give up with posting code, simply: there should be ?php not just ? at script opening
Been playing around with nginx on a CentOS 5.5 VirtualBox install for a few days now. It’s been a straight nightmere dealing with spawn-fcgi in conjuction with nginx and CentOS. These instructions worked perfectly for me. Also added php-mysql and php-gd without any issues. Great job and thank you so much for sharing this. Couldn’t be happier right now. Bookmark set.
Thanks again,
Stefan
work perfectly great!
Great tutorial,
how about define virtual host ? can you make a tutorial too about that ?
I try some times but it not work
Thanks. Sure. I’ll try to put one together.
Thanks for the great tutorial.
When executing “yum install php53-fpm php53-pecl-apc”
I am getting “No package php53-fpm available.”
I searched with ‘yum list’ for packages with similar names but found nothing.
Can you please help?
Found the answer here:
http://blog.dengruo.com/201009/978
Instead of:
yum install php53-fpm php53-pecl-apc
I used:
yum install php53-pecl-apc
rpm -ivh http://dl.iuscommunity.org/pub/ius/stable/Redhat/5.5/x86_64/php53-fpm-5.3.3-4.ius.el5.x86_64.rpm
yum install php53-fpm
The linked blog is currently unavailable so I’ll have to check later to see what the referenced answer is.
I’m not sure why the package is not available for you. I just tested it again and it found the packages fine. You could try “yum clean all” to force yum to update the list of packages. Glad you figured it out though.
I was under the impression php 5.3.3 included php-fpm?
Yes and no. PHP 5.3.3 now includes PHP-FPM within the PHP source but still requires a configure/compile switch to enable it (–enable-fpm).
The php53 package from IUS does not build in the PHP-FPM while the php53-fpm package does build it in but into a separate binary (/usr/bin/php vs /usr/sbin/php-fpm since it’s designed to be a server) and also provides the surrounding configs, init.d script, etc.
The separation of the two binaries feels well designed and cleaner to me.
Hey, thanks a lot for the guide. It has been very useful. Is there any reason for installing nginx 0.7.65 instead of the newer 0.8.53?
Yum, now I see that when you wrote the article the 0.8 branch was not a stable version
Yup that’s correct. I noticed this myself about a week ago but forgot to update this post. Thanks for reminding me.
A few steps is missing.
Disable apache before trying to start nginx. I got a listen to port 80 error.
So service httpd stop and maybe a way to stop it from starting at boot up.
If you got php installed allready this worked for me.
yum remove php*.*
apc could be updated, 3.1.16 has been released.
If you are using Zend for WHMCS or any other PHP 5 script, this install won’t work.
PHP 5.3+ isn’t supported by Zend yet, and will take some manual coding of your Zend PHP scripts to make it work.
Zend only supports upto PHP 5.214, just an fyi.
Mike
Mike, you obviously wrong here since zend says it supports PHP 5.3 in Zend framework 1.9 release.
Ref – http://www.zend.com/en/company/news/press/zend-framework-features-php-readiness-and-new-professional-components
hrmm, wanted to play around and found this, everything works up until i go to open the page in a browser, it dwonloads instead of renderin ghte php, what am I missing?
I’m going to need more info. Are you attempting to view the phpinfo.php file?
Doh, dont comment out
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; but remove/delete the line
silly badtz.
and thank you, this was simple concise and minus my typos worked with no issues on 5.5 as of today. I did have to change some paths but that was easy enough. Thanks for a great tutorial.
Hey,
I think as Jan 04-11 the packages are now called php53u-fpm and php53u-pecl-apc
Attempting to install right now .. just waiting for yum remove php to finish
Took me ages… this comment is a lifesaver! it would be really helpful to update the tutorial, it is an excellent clear one.
Any tips on how to get php53-sqlite installed ? There’s no IUS package…
Hi, Everything works fine untill I setup a WordPress, it says ‘Sorry, but I can’t write the wp-config.php file.’ and I have to manually add that file, I think there’s something wrong with file permissions, I downloaded and unzipped WordPress via wget the, I see the default owner group is 33:33, I’m not very good at CentOS. Any suggestion? Thanks.
Aha, I found that: in /etc/php-fpm.d/www.conf, change the user and group from apache to nginx (I complied nginx with –user=nginx –group=nginx), and then restart php-fpm, then it seems works. cheers.
Just one problem. it seems that php-fpm doesn’t automatically start after VPS rebooting.
add “service php-fpm restart” in /etc/rc.d/rc.local .
When I go to the last step I get the following error:
# service nginx start
Starting nginx: [emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
[emerg]: still could not bind()
[FAILED]
LNMP ???
Hi, I’ve just gone through this on a clean CentOS 5.6 (freshly yum updated, Jun-1-11) 64bit OpenVZ VM. Install goes smoothly; there was an issue with a bit of whitespace in the fastcgi_param line if direct copy-paste from textbox above; but once that is clear nginx starts up fine; and php-fpm processes are runing as is nginx. However when I visit a phpinfo page – all I get is blank (zero content returned). This sounds similar to the first poster in this forum .. I’m unclear, is there any obvious / known reason why this might be the case ? Thanks! –Tim
A footnote: After a nights sleep; reviewed my config again. Problem was that I copy-pasted the php stanzas (rather than uncommenting existing ones already present in the default nginx.conf file); this resulted in unexpected behaviour (things were broken). The cause for ‘blank page’ was that the path ‘didn’t exist’ for the ‘root’ line stanza. Adjusted this line, restart nginx, bouf, things work fine. This after reading other various online hints, especially one comment from URL, “https://bbs.archlinux.org/viewtopic.php?id=101750″ which stated nicely, “The blank page is a silent error saying “this script doesn’t exist”.
Anyhoo . I hope this might help someone else doing the walk through, maybe. Great guide, BTW!
Tim
Does the file ‘php53u-fpm’ include a full install of PHP5.3? All I’m really after is an RPM based php-fpm. I have everything working with nginx / PHP / php-fpm, the only thing I don’t have is an init.d script for php-fpm so if the server is rebooted I have to start that manually
Pingback: 启程 | blog.im942.com
Pingback: Apache Alternatives for Serving PHP | Wazi
Pingback: Apache Alternatives for Serving PHP | radworx.com
Pingback: CentOS 5.5 + PHP 5.3.3 + PHP-FPM + APC + nginx (yum RPMs) | 佳良_技術筆記本
Pingback: » Linuxaria – Everything about GNU/Linux and Open source Apache Alternatives for Serving PHP
Hi just wanted to say thank you!
I’ve been struggling with PHP to get it to work for hours!
You probably also want to add MySQL support, which is extremely easy once you find it;
Just add “php53u-mysql” to the “yum install php53u-fpm php53u-pecl-apc” line.
Again, thanks!
Thank You, it works perfect!
You can also add php-mysql support;)
Worked very well for me on RHEL 6.
Only change:
baseurl=http://dl.iuscommunity.org/pub/ius/stable/Redhat/6/x86_64/
Thanks a lot.
Very nice and simple post…I installed Nginx and PHP-FPM in CentOS 5.6 without any issue and now running it happily! The comments also helped as well.
so many thanks !! .. worked like a charm at first try in a recently installed centos 57 !!
just a few advices:
- ius repo official page is mentioned at official php downloads page
- you may correct your paths and your versions
- if you run php at same machine as nginx, you may try unix sockets instead tcp
edit /etc/php-fpm.d/www.conf , line 12:
listen = /var/lib/php/php-fpm.sock
edit /etc/nginx/nginx.conf , section “location ~ \.php {”
#fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/var/lib/php/php-fpm.sock;
- additionally you can include ‘service php-fpm start|stop’ in nginx initscript
see you