phpMyAdmin 404 error on Digital Ocean hosting

February 24, 2017 629 views
Nginx LEMP Ubuntu 16.04

I'm getting a 404 error after install phpMyAdmin using Digital Ocean's guide. I have multiple domains setup on Ubuntu running nginx. There is a phpmyadmin directory within /var/www/. The only difference from the guide was the following command:

sudo ln -s /usr/share/phpmyadmin/ /var/www

Do I need to add server block possibly? Since I have multiple domains, each of them has a separate configuration file.

Sample config file:

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/domain1.com/html;
    index index.php index.html index.htm index.nginx-debian.html;

    server_name MY_IP_ADDRESS;

    location / {
        try_files $uri $uri/ =404;
    }

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

    location ~ \.php$ {
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root/$fastcgi_script_name;
        include        fastcgi_params;
        try_files      $uri /index.php;
    }

    location ~ /\.ht {
        deny all;
    }
}

Any suggestions?

2 Answers

@smallgiants

For the location /phpmyadmin block, you may want to use alias instead of root. You also want to set either the root or alias to the actual directory that phpMyAdmin is located in.

So if /var/www/phpmyadmin exists (even as a symlink), then you want to use:

root /var/www/phpmyadmin;

or

alias /var/www/phpmyadmin;

You also shouldn't need the try_files $uri /index.php; definition in the block that handles your PHP / PHP-FPM request processing. Ideally you'd set that per block as that gives you more control over what happens within each location.

For example, WordPress may handle rewrites differently than Drupal, which will handle them differently than phpMyAdmin (if it does at all), etc.

The 404 error is resulting as index.php doesn't exist in /var/www, which is where it's looking when a request for /phpmyadmin is routed.

I'm install centos or vpssim on DO is good

Have another answer? Share your knowledge.