Recently we have been playing around with nginx for a couple of projects we have been working on and I think I have fallen in love with a web server. After using apache for so many years, I did not think that this could be possible, but it is!! For what we are using it for, it is superior in almost every aspect: installation, configuration, speed, memory usage, etc. Not to mention the fact that most of our apache deployments are often tainted by the beast that is cPanel/WHM… The reason I am writing this article is to hopefully alleviate the pain of trying to figure out how to setup phpmyadmin or other such applications in a non-document root setup when you are just learning the ins-and-outs of nginx configuration.
Just a quick tip because it is probably the main stumbling block when learning nginx configuration vs apache configuration; the root directive works differently in nginx. In nginx it will append the directory from the matching location block to the request. Taken from the docs: “so that a request for “/i/top.gif” will not look in “/spool/w3/top.gif” [but in /spool/w3/i/top.gif] like might happen in an Apache-like alias configuration where the location match itself is dropped. Use the alias directive to achieve the Apache-like functionality.” But I digress.
Most of the online documentation and tutorials explain how to get php running globally or how to get phpmyadmin to work from document root, but I had to dig deep to get it to work like www.domain.com/phpmyadmin/ . I didn’t want every .php script to be run as php and I did not want phpmyadmin installed at document root. Here is what I found:
location /phpmyadmin {
root /usr/local/nginx/html;
index index.php;
}
location ~ ^/phpmyadmin.+.php$ {
root /usr/local/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
(more…)