phpMyAdmin – Configuring phpMyAdmin with nginx on Fedora 17 for Localhost Access

fedoralinuxnginx

[Tried all answers on Stackoverflow, and searched on google a lot, but none of the configurations worked.]

I've installed LEMP server on Fedora using the guide on DigitalOcean (https://www.digitalocean.com/community/articles/how-to-install-linux-nginx-mysql-php-lemp-stack-on-centos-6). Replaced example.com in nginx's default.conf to localhost.

Then, I installed phpMyAdmin using this (https://www.digitalocean.com/community/articles/how-to-install-phpmyadmin-on-a-lemp-server).

The nginx web directory is /usr/share/nginx/html. I've created a symbolic link for phpmyadmin. It's at /usr/share/nginx/html/phpMyAdmin.

Currently, I just need localhost access (localhost/phpmyadmin). I'm able to access localhost, and localhost/info.php.

I tried many configurations, one of them below: Nginx location directive doesn't seem to be working. Am I missing something?

But it doesn't work. Sometimes I get "No input file specified." and other times 404 not found. I'd like to have the access at localhost/phpmyadmin.

Edit:
My default.conf file. Getting a "No input file specified." error in browser.

#
# The default server
#
server {
    #listen       80 default_server;
    listen  80;
    server_name localhost;
    #server_name  _;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index index.php index.html index.htm;
    }

    location /phpmyadmin {
        alias /usr/share/nginx/html/phpMyAdmin;
        index index.php index.html index.htm;
    }

    error_page  404              /404.html;
    location = /404.html {
        root   /usr/share/nginx/html;
    }

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ /phpMyAdmin/.*\.php$ {
        fastcgi_pass    127.0.0.1:9000;
        fastcgi_index   index.php;
        fastcgi_param   SCRIPT_FILENAME /usr/share/nginx/html/$uri;
        include     fastcgi_params;
    }

    location ~ \.php$ {
        root           /usr/share/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;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

Thanks.

Best Answer

For your 404, you should make the character cases match either all phpmyadmin (all lower case) or phpMyAdmin.

To make the config clearer (my opinion), you could use nested locations:

location /phpmyadmin/ {
    index index.php index.html index.htm;

    location ~ \.php$ {
        fastcgi_pass    127.0.0.1:9000;
        fastcgi_index   index.php;
        fastcgi_param   SCRIPT_FILENAME /usr/share/nginx/html/$uri;
        include     fastcgi_params;
    }
}

You then have to relink phpMyAdmin in your webroot (note the missing alias directive):

unlink /usr/share/nginx/html/phpMyAdmin
ln -s /usr/share/phpMyAdmin /usr/share/nginx/html/phpmyadmin


Alternatively, to keep the mixed-case link, add this line to the above location /phpmyadmin to internally change the $uri (required to find the files):

rewrite ^/phpmyadmin(.*)$ /phpMyAdmin$1;


To fix the 500, you might want to check out another answer on SF about PHP restrictions. I just now realized that executing PHP scripts outside the webroot can trigger security mechanisms.
That would then be a PHP error, meaning that the location matches.