Nginx + fcgi (fastcgi) + PHP + APC + Zend Framework + CentOS

My newest toy I’ve been playing with is Nginx. Getting PHP to work over FastCGI. The performance gain over Apache + mod_php is quite staggering.

Here are a few things to watch out.

Getting PHP v5.2

Some of my apps are not ready to make the jump to PHP 5.3 just yet, so I needed to get a hold of PHP 5.2. In the past I just install the Zend Server CE it would have all the PHP bells and whistles I could ever need. Not anymore, now it’s time to fend for myself.

Webtatic Repo

http://www.webtatic.com/blog/2009/06/php-530-on-centos-5/

I’ve added webtatic to my repos and followed his advice to disable PHP 5.3 from his repos you add exclude=php*5.3* to your webtatic.repo file.

Now you can install PHP.

APC Opcode Cache

This waa a little more of struggle as I need to install various things to get it to work. I finally ran pecl install apc and it compiled fine. Then I added a file

/etc/php.d/apc.ini

extension=apc.so

PHP will pick that up and just enable it. Make sure to check that it’s enabled by running phpinfo(). Also you can download the source and extract the file apc.php Throw this on your server and run it in the browser, it will give you a nice rundown about the state of APC and let you know if it’s working.

PHP via FastCGI

There are a few ways to accomplish this and much debate on which is the best way, but I followed the instructions on

http://www.cyberciti.biz/faq/rhel-fedora-install-configure-nginx-php5/

It lays it out plain, how to get a FastCGI daemon going. One change I did make though. It has the daemon listening on localhost:9000. I changed my to a socket located at /tmp/phpcgi.socket

Here is the /etc/init.d/php_cgi init script.

Zend Framework

One issue I ran into with Zend Framework, was the location of the sessions folder and the permissions. The default session folder is in /var/lib/php/session this was owned by apache, I just changed the owner:group to nginx:nginx. All was sunshine and roses again.

One Response to Nginx + fcgi (fastcgi) + PHP + APC + Zend Framework + CentOS

  1. Great article! Just to check…did you do this on a clean Centos install or did you already have Zend Server CE running on it? I’m debating on the best server platform and read your previous article on Zend Server CE. I was considering Centos 5.5 and Zend Server CE (PHP 5.2). I’m guessing the performance you’ve got here beats that and it’s worth the hassle?

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">