Since this article has been published long time ago, there is MUCH better option to manage PHP FastCGI processes than the one I described below. Please check out php-fpm project from Andrei Nigmatulin which IMHO is the best possible way to manage PHP processes.

Nginx supports FastCGI technology to work with many external tools and servers. PHP itself can be runned as FastCGI application and can process FastCGI requests from nginx.

So, first of all we need to install PHP with fastcgi support and run it on some local tcp port. Installation process can go different ways, but I will describe here how to compile PHP from sources because it is generic way. To get fastcgi-enabled version of PHP interpreter, you may use following commands:

# clean environment and set up a new onenohupenv - $Esh-c"$EX"&>/dev/null &

If you want to use third party software to start PHP as FastCGI-server,you can take a look at spawn-fcgi from Lighttpd project.

So, your PHP FastCGI server has been started and now last thing you need to do is to configure nginx server to forward php-requests to PHP’s tcp-port. It can be done with following config file snipet (full version is here):

That is all! Now you can use your nginx to serve any PHP-enabled sites and its performance will be very close to Apache mod_php module, but you will get more memory to process more requests from your site visitors.

As always, if you have some questions or suggestions, you can post them in comments area or email me. If you like this article, please vote for it on digg.com.