39009a4f0b581c3668b0bc5f2f626e8883c63a03
By:
javadroid

PhpMyAdmin got 404 not found error on nginx ubuntu 16.04

April 4, 2017 27k 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 :)

6 Answers
jtittle1 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

      • You have to remove old symlink like this :
        sudo rm -rf /usr/share/nginx/html
        and create a new one like this:
        sudo ln -s /usr/share/phpmyadmin/ /var/www/phpmyadmin
        as your root is
        root /var/www;
        and not
        root /var/www/html;

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.

gracias me ha funcionado correctamente

I had nginx, phpmyadmin, mariadb, php-fpm on a centos 7. now i just update php5 to php7. and phpmyadmin is not found. so i followed all your steps.even restart nginx, php-fpm. ls -l showing phpmyadmin in my server location directory. but in browser its showing 404. its chown by root:root and chmod 777. phpmyadmin -> /usr/share/phpmyadmin.
i know upgrading to php7 uninstall old one, so i download and properly extract phpmyadmin in /usr/share/ directory.
no error log found in php/nginx error log files. any idea??

Hello Digital Oceans, I had nginx, phpmyadmin, mysql, php7.2-fpm on a Ubuntu
in browser on 159.89.106.31/phpmyadmin - "couldn't find this page"

I can not configure phpmyadmin
Help me, what am I doing wrong?

My /etc/nginx/sites-available/default
server {
listen 80 defaultserver;
listen [::]:80 default
server;
root /var/www/html/public;
index index.html index.htm index.php;
servername 159.89.106.31;
location / {

try
files $uri $uri/ /index.php$isargs$args;
}

location ~ .php$ {
include snippets/fastcgi-php.conf;

fastcgi
pass unix:/run/php/php7.2-fpm.sock;
}

}

My /etc/nginx/nginx.conf

user www-data;
errorlog /var/log/nginx.errorlog info;
worker_processes auto;
pid /run/nginx.pid;

events {
worker_connections 768;

}

http {
##
# Basic Settings
##
disablesymlinks off;
sendfile on;
tcp
nopush on;
tcpnodelay on;
keepalive
timeout 65;
typeshashmaxsize 2048;
include /etc/nginx/mime.types;
default
type application/octet-stream;
sslprotocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl
preferserverciphers on;
accesslog /var/log/nginx/access.log;
error
log /var/log/nginx/error.log;
gzip on;
gzip_disable "msie6";
include /etc/nginx/conf.d/.conf;
include /etc/nginx/sites-enabled/
;
}

I add link sudo ln -s /usr/share/phpmyadmin/ /var/www/html/phpmyadmin
lrwxrwxrwx 1 root root 22 Mar 13 07:38 phpmyadmin -> /usr/share/ph pmyadmin/

Add /etc/nginx/sites-available/default, copy this script in server{ ..copy here.. }
location /phpmyadmin {
root /usr/share/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+.php)$ {
tryfiles $uri =404;
root /usr/share/;
fastcgi
pass 127.0.0.1:9000;
fastcgiindex index.php;
fastcgi
param SCRIPTFILENAME $documentroot$fastcgiscriptname;
include /etc/nginx/fastcgi_params;
}
location ~* ^/phpmyadmin/(.+.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/;
}
}
location /phpMyAdmin {
rewrite ^/* /phpmyadmin last;
}
in browser on 159.89.106.31/phpmyadmin 502 Bad Gateway

  • working version
    Attention - php7.2-fpm.

    server {
    listen 80 defaultserver;
    listen [::]:80 default
    server;
    root /var/www/html/public;

    index index.html index.htm index.php;
    servername IPaddresyouserver ;
    location / {
    tryfiles $uri $uri/ /index.php$isargs$args;
    }

    location ~ .php$ {
    include snippets/fastcgi-php.conf;

    fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
    }
    location /phpmyadmin {
    root /usr/share;

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

    }

Have another answer? Share your knowledge.