Get phpMyAdmin to work with Nginx

To get phpmyadmin to work with Nginx, here are the things need to add into /etc/nginx/sites-available/default

One thing to take note, the root suppose to be /usr/share but not directly /usr/share/phpmyadmin.

location /phpmyadmin{
     root    /usr/share;
     index   index.php;

location ~ \.php$ {
     set $php_root   $document_root;
         if ($request_uri ~* /phpmyadmin) {
             set $php_root /usr/share;

     fastcgi_index index.php;
     fastcgi_param  SCRIPT_FILENAME  $php_root$fastcgi_script_name;
     include /etc/nginx/fastcgi_params;

As for the location to handle php file. Here is an explanation why the directive will get error


Nginx and PHP on Ubuntu 10.10

Taken from the steps at, but with some modifications.

To install Nginx in Linux

$sudo apt-get install nginx

Also install PHP at the mean time

$sudo apt-get install php5-cgi php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl

add the line cgi.fix_pathinfo = 1 right at the end of the file php.ini

$vim /etc/php5/cgi/php.ini

Then install lighttpd

$sudo apt-get install lighttpd

$sudp update-rc.d -f lighttpd remove

$sudo /usr/bin/spawn-fcgi -a -p 9000 -u www-data -g www-data -f /usr/bin/php5-cgi

add the above line to for next boot up

$sudo vim /etc/rc.local


After that make changes to the conf files at /etc/nginx/nginx.conf and related files in site-available folder. Steps are similar to the pointed link.