The following tutorial is done with Debian Squeeze version 6.0.2.
In this tutorial, I will show you the shortest and easiest way to set up nginx with PHP5, MySQL and phpmyadmin running through FastCGI:
Step 1: Installation:
apt-get install nginx mysql-server mysql-client php5 php5-cgi php5-mysql phpmyadmin
NOTE: After you have installed all above you will need to edit the php.ini file:
Open php.ini file end remove the ; in front of the line cgi.fix_pathinfo=1
Step 2: Make PHP FastCGI daemon listening on port 9000 on localhost and start at boot.
Edit the /etc/rc.local file and put the following content:
vim /etc/rc.local
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid
Step 3: Create virtual host file for your site:
Now, you create the virtualhost file in the /etc/nginx/sites-available folder.
You will enable the site just created with the following command:
ln -s /etc/nginx/sites-available/yoursitename /etc/nginx/sites-enabled/yoursitename
/etc/init.d/nginx restart
Example config for virtualhost files:
server {
listen 80;
server_name www.debian-tutorials.com;
access_log /var/log/nginx/debian-tutorials.log main;
root /var/www/debian-tutorials.com;error_page 404 /404.html;
location = /404.html {
root /var/www/;
}error_page 403 /403.html;
location = /403.html {
root /var/www/;
}error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/;
}location / {
index index.php;if (-f $request_filename) {
expires 30d;
break;
}
if (!-e $request_filename) {
rewrite ^(.+)$ /index.php?q=$1;
}}
location ~* ^.+\.(gif|png|ico|css|js|jpg|jpeg|html|htm)$ {
access_log off;
expires 30d;
}location ~ \.php$ {
fastcgi_buffers 8 32k;
fastcgi_buffer_size 32k; fastcgi_pass 127.0.0.1:9000;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
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_FILENAME /var/www/debian-tutorials.com$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT /var/www/debian-tutorials.com;
fastcgi_param SERVER_PROTOCOL $server_protocol;
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;
fastcgi_param REDIRECT_STATUS 200;
fastcgi_index index.php;
fastcgi_intercept_errors on;
}location ~ /\.ht {
deny all;
}
}
Step 4: Now enabe PhpMyAdmin for http://www.debian-tutorials.com
Just create one simlink from PhpMyAdmin foler to Debian-tutorials.com folder:
ln -s /usr/share/phpmyadmin /var/www/debian-tutorials.com/phpmyadmin
Step 5: Restart nginx to load all configs:
/etc/init.d/nginx/restart
Now you can access PhpMyAdmin without getting any problems using the link: http://www.debian-tutorials.com/phpmyadmin/
Enjoy.

July 19th, 2011 on 10:53
The Debian repos did not include the latest stable version of NGinx. I f you want to install the latest one, you can also use this shell script:
https://github.com/nicolargo/debianpostinstall/blob/master/nginxautoinstall.sh
July 19th, 2011 on 12:07
or you can use try following :
nginx=stable # use nginx=development for latest development version
echo “deb http://ppa.launchpad.net/nginx/$nginx/ubuntu lucid main” > /etc/apt/sources.list.d/nginx-$nginx-lucid.list
apt-key adv –keyserver keyserver.ubuntu.com –recv-keys C300EE8C
apt-get update
apt-get install nginx
enjoy
August 11th, 2011 on 09:53
Edit the /etc/rc.local file and put the following content:
vim /etc/rc.local
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid
Where did you get it from??? spawn-fcgi
All of a sudden put the following….no explaination…
August 11th, 2011 on 11:17
the explanation is:
we will use that command to start the PHP FastCGI daemon listening on port 9000 on localhost and running as user www-data group.