Building PHP Webserver on Nginx with PHP CGI

Doesn’t like the Apache webserver, nginx didn’t have the auto-configuration feature from PHP and library loading. The way to make nginx be a PHP webserver is passing the request to PHP CGI. How?

The first step must be installing the nginx and php5 package. For this post i’m using Ubuntu 10.04 LTS.

apt-get update nginx
apt-get update php5

Check your nginx installation with start the service:

service nginx restart
/etc/init.d/nginx restart

Now, if the nginx working, let’s connect it to the PHP CGI. First, run the PHP CGI so that the PHP listen at with port 9000.

/usr/bin/php-cgi -b &

After the CGI is running, go to nginx configuration and make a script pass to PHP CGI.

	listen 80 default;
	server_name	_;

	root		/var/www/nginx-default;
	index		index.html index.php;

	location ~ .php$
		fastcgi_index  index.php;
		include /etc/nginx/fastcgi_params;
		fastcgi_param  SCRIPT_FILENAME  /var/www/nginx-default$fastcgi_script_name;

Leave a Reply

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

Post Navigation