2

I have spent almost the entire day debugging this issue with my phpmyadmin installation getting error 404 when I run it using Nginx. I have Googled several pages online, but no solution has worked. However, when I run phpmyadmin as a domain, it works!!

I want to access phpmyadmin as directory such as http://my-server-ip/phpmyadmin

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

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

        server_name _;

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

        location /phpmyadmin {
            access_log /var/log/nginx/phpmyadmin_access.log;
            error_log /var/log/nginx/phpmyadmin_error.log;

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

            include snippets/fastcgi-php.conf;
            fastcgi_param SCRIPT_FILENAME /usr/share/phpmyadmin/index.php;
            fastcgi_param SCRIPT_NAME /index.php;

        }

        location ~ \.php$ {
                #fastcgi_pass    127.0.0.1:9000;
                fastcgi_pass   unix:/run/php/php7.1-fpm.sock;
                include snippets/fastcgi-php.conf;
                fastcgi_param  SCRIPT_FILENAME  /usr/share/phpmyadmin$fastcgi_script_name;
      }

}
David Okwii
  • 324
  • 1
  • 5
  • 13

3 Answers3

1

You got 404 because nginx is looking for 'phpmyadmin' in '/usr/share/phpmyadmin/'. It means '/usr/share/phpmyadmin/phpmyadmin' Replace 'root' with 'alias' https://nginx.ru/en/docs/http/ngx_http_core_module.html#alias to solve it.

example:

location /phpmyadmin {
        alias   /usr/share/phpmyadmin;
        index  index.php;
        fastcgi_param SCRIPT_FILENAME /usr/share/phpmyadmin/index.php;
        fastcgi_param SCRIPT_NAME /index.php;
        fastcgi_pass   php-fpm;
    }
  • It turns out you are right. Now the browser can load the phpmyadmin. There's one more problem though; chrome or firefox display a blank page even though I have configured the html/js/css code loads from developer console. It's weird. The error is "There is mismatch between HTTPS indicated on the server and client. This can lead to non working phpMyAdmin or a security risk. Please fix your server configuration to indicate HTTPS properly" – David Okwii Jun 26 '18 at 20:04
  • have you checked it https://docs.phpmyadmin.net/en/latest/config.html#cfg_Servers_ssl ? – Alexander Makarenko Jun 27 '18 at 11:12
1

I finally got it working with the following config;

server {
    listen   80 default_server;

    access_log /var/log/nginx/phpmyadmin_access.log;
    error_log /var/log/nginx/phpmyadmin_error.log;

    # Main application:
    root /var/www/html;
    index index.php index.html index.htm;

    # phpMyAdmin:
    location /phpmyadmin {
        root /usr/share;
        index index.php;
    }
    # PHP files for phpMyAdmin:
    location ~ ^/phpmyadmin(.+\.php)$ {
        root /usr/share;
        index index.php;
        #fastcgi_read_timeout 300;
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.1-fpm.sock;
    }

    # PHP files for the main application:
    location ~ \.php$ {
        fastcgi_read_timeout 300;
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.1-fpm.sock;
    }
}
David Okwii
  • 324
  • 1
  • 5
  • 13
0

Here is few things you should check:

  1. First of all, check tail /var/log/nginx/error.log
  2. Check is www-data owner of phpMyAdmin directory
  3. In nginx configuration, check is location /phpmyadmin above location ~ .php$
  4. Be aware of lower and upper cases, phpMyAdmin and phpmyadmin directories are not the same
  5. Check fastcgi_pass unix:/run/php/php7.1-fpm.sock; - do you have this PHP-FPM version installed on your server