Setting up NGINX, PHP with CGI on Ubuntu 10.10 Linux

1. Installing

apt-get install nginx php5 php5-cgi php5-cli

2. Make your site folder under document root

mkdir -p /var/www/newsite
chown -R www-data www-data /var/www/

3. Create new file /etc/nginx/sites-available/newsite and put below entries in it

server {
listen 80;
server_name newsite.com www.newsite.com;
access_log /var/logs/nginx/access.log;
error_log /var/logs/nginx/error.log;

location / {
root /var/www/newsite;
index index.html index.htm index.php;
}

location ~ .php$ {
fastcgi_param SCRIPT_FILENAME /srv/www/newsite$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
}
}


4. Create symlink of above file
ln -s /etc/nginx/sites-available/newsite  /etc/nginx/sites-enabled/newsite

5. Restart Nginx

/etc/init.d/nginx restart

6. Spawn fcgi with below command

/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 6 -u www-data -f /usr/bin/php5-cgi


7. Test with testpageCreate one test php script under /var/www/newsite/   say test.php Put below php code in that file

<?php
   phpinfo();
?>

8. put below entry in your host file for testing

127.0.0.1             newsite.com  www.newsite.com

9. Visit now http://newsite.com/test.php from same machine.
It should show PHPinfo page.
🙂

Neelesh Gurjar has written 122 articles

Leave a Reply