39009a4f0b581c3668b0bc5f2f626e8883c63a03
By:
javadroid

PhpMyAdmin got 404 not found error on nginx ubuntu 16.04

April 4, 2017 804 views
Linux Commands Nginx Ubuntu 16.04

Hello Digital Oceans,
I'm using ubuntu 16.04 and configured LEMP with this tutorial on it. I tried to add phpMyAdmin with this tutorial , but when I tried to access /phpmyadmin route, I got 404 error. here is my default site-available config file:

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

        root /var/www/html;

        index index.php index.html index.htm index.nginx-debian.html;

        server_name **My_IP_ADDRESS**;

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

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        }

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

Am i miss something?
Thank you,
JavaDroid :)

3 Answers
jtittle April 4, 2017
Accepted Answer

@javadroid

The symlink created in that guide points to /usr/share/nginx/www while your root directive points to another directory. Unless you specify another location block, NGINX doesn't technically know that the directory exists, and doesn't know where to route the incoming request.

First, remove the symlink you just created by running:

rm -rf /usr/share/nginx/www

That won't delete phpMyAdmin, it'll just delete the symlink. Now we'll create a new one using:

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

Since you've set root to /var/www/html, that's your "home" directory or root path that your server block uses. What the above command does is create a symlink from where the phpMyAdmin files are to your root directory.

Once the new symlink is there, you should be able confirm that by running:

ls -al /var/www/html

That should produce something that looks like:

lrwxrwxrwx 1 root root   22 Apr  4 14:31 phpmyadmin -> /usr/share/phpmyadmin/

Which means the symlink is valid and should now work when you visit:

http://IP_ADDR/phpmyadmin

Where IP_ADDR is your IP address.

  • Thaaanks man !!! it works !!

  • Hi,
    I am very new in LEMP and installed all expect phpmyadmin and working fine. I followed above steps after getting 404 not found error for phpmyadmin but still same issue. help is appreciated.

    Thanks.

Hi,
I am very new in LEMP and installed all expect phpmyadmin and working fine. I followed above steps after getting 404 not found error for phpmyadmin but still same issue. help is appreciated.

Thanks.

  • have you fixed or facing same issue ?

    • HI @ArfanMirza,
      Thanks for your reply.
      I am having the same issue so I am using Mysql Workbench.
      Here is my nginx.conf server block.

      server {
      listen 80 defaultserver;
      listen [::]:80 default
      server;

          root /var/www;
          index index.php index.html index.htm;
      
          server_name localhost;
      
          location / {
              autoindex on;
                  autoindex_exact_size off;
              try_files $uri $uri/ =404;
          }
      
          location ~ \.php$ {
              include snippets/fastcgi-php.conf;
              # With php7.0-cgi alone:
              #fastcgi_pass 127.0.0.1:9000;
              # With php7.0-fpm:
              fastcgi_pass unix:/run/php/php7.0-fpm.sock;
          }
      }
      

      Thanks in advance

Here is my code block

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

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

    server_name auliyakaram.com www.auliyakaram.com;

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

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }

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

Follow this

https://www.digitalocean.com/community/questions/phpmyadmin-got-404-not-found-error-on-nginx-ubuntu-16-04

First, remove the symlink you just created by running:

rm -rf /usr/share/nginx/www

That won't delete phpMyAdmin, it'll just delete the symlink. Now we'll create a new one using:

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

https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-phpmyadmin-with-nginx-on-an-ubuntu-14-04-server

AND

sudo php5enmod mcrypt ==> if failed then
locate *enmod
You will find the enmod name if installed with php, i found this
/usr/sbin/phpenmod
so execute 'sudo phpenmod mcrypt'

sudo service php5-fpm restart ==> if failed then
locate *-fpm
You will find the correct fpm name i found this
/etc/init.d/php7.0-fpm
then
executesudo service php7.0-fpm restart

finally then

http://server_domain_or_IP/phpmyadmin

Now hopefully, you will get phpmyadmin home page.

But after login may be it give 404 error! dont worry just go to browser url and append phpmyadmin again before index.php?token=xxxxxxxxxxxxxxxxxxxx

http://server_domain_or_IP/index.php?token=xxxxxx to http://server_domain_or_IP/phpmyadmin

If still error, just let me know, i am here for you any time!

by Justin Ellingwood
Administering relational databases from the command line can be a daunting proposition for many people. A project called phpMyAdmin aims to alleviate this issue by providing an easy to use web interface for MySQL. In this guide, we'll discuss how to install and secure phpMyAdmin on top of a LEMP (Linux, Nginx, MySQL, and PHP) stack on an Ubuntu 14.04 server.
Have another answer? Share your knowledge.