Skip navigation.
Home

Compiling PHP as a CGI for Nginx

Y'all may have heard about a new upstart web server, Nginx. The product of a single Russian programmer, it's gaining a lot of traction as a viable alternative to heavyweights like Apache, while in some cases outperforming them.

I recently wanted to experiment with the server, but couldn't see much utility without it being able to process my favorite scripting language, PHP.

Nginx, delightfully, can run PHP but only through a FastCGI interface. Most of the instructions I found on the web pointed me to the PHP-FPM website. As of this writing, there were two methods to install PHP-FPM: applying a patch directly to the PHP source prior to compilation, or using LaunchPad (we're ignoring the third experimental option).

If this process is too complicated or convoluted, or you want to get up and running more quickly with a welterweight CGI processor, it turns out that the PHP CGI binary can run just fine with Nginx as is.

The PHP CGI binary provides a switch, -b, which takes an IP address and port number (127.0.0.1:9000) and runs in daemon mode. Voila! And no extra hassle downloading extra libraries, scripts, etc. Just compile PHP per the usual fashion, and it should build a PHP CGI binary.

Postscript: native support for PHP-FPM in the PHP core is on the horizon.

see more related to: