lots of tech info here

Configuring Nginx to include PHP FastCGI support

Configuring Nginx | Nginx with mod_php

Install these on the command line:

  apt-get install php5-cli php5-cgi php5-xcache build-essential

Download and install spawn-fcgi 1.6.2:

wget http://www.lighttpd.net/download/spawn-fcgi-1.6.2.tar.bz2
tar -xjvf spawn-fcgi-1.6.2.tar.bz2
cd spawn-fcgi-1.6.2
./configure
make
make install

Create a script to start PHP processes as FastCGI:

  touch /usr/bin/php-fastcgi

FastCGI PHP will run on port 10005. Edit it and add this:

#!/bin/sh
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 10005 -u www-data -f /usr/bin/php5-cgi

Edit /etc/nginx/sites-enabled/default and add this in the server block

# php requests
location ~ .*\\.php?$ {
    include /etc/nginx/fastcgi_params;
    fastcgi_pass  127.0.0.1:10005;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /home/username/public_html/imacstercom$fastcgi_script_name;
}

Contents of /etc/nginx/fastcgi_params

fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

Run /usr/bin/php-fastcgi and restart nginx

sudo /usr/bin/php-fastcgi
sudo /etc/init.d/nginx restart

See if Nginx serves PHP pages. Create a simple PHP script called info.php with these contents:


And navigate to http://imacster.com/info.php to see if it works.

Alternative to PHP FastCGI

Configuring Nginx | Nginx with mod_php

Updated on 01 Jul 2009 {Created on 02 Jul 2009}

If you liked this article, subscribe to our Feed, follow us on Twitter (@aruljohn) and/or join our Facebook Page.

Share this with Others

Subscribe

Tags