phpMyAdmin is a very popular tool for managing MySQL databases. It can do many things, from modifying data to optimizing databases. But, the one thing it lacks by default is NGINX support. Just running sudo apt install phpmyadmin has support for Apache and Lighttpd, but nothing for NGINX.


To install phpMyAdmin, simply run:

sudo apt install phpMyAdmin

and if you’re prompted for which web server to configure, select nothing and continue the install. All files will be placed in /usr/share/phpmyadmin.


I prefer to make a symlink instead of telling NGINX to read files directly from /usr/share. So, run:

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

and you now have the equivalent of a folder containing phpMyAdmin in /var/www/phpmyadmin.

Next, create a file(/etc/nginx/sites-available/phpmyadmin.conf), and place the following in:

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

        index index.php;
        root /var/www/phpmyadmin;

        location /{
                try_files $uri $uri/ index.php;

        location ~ \.php$ {
               fastcgi_index index.php;
               try_files $uri =404;
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;
               include /etc/nginx/fastcgi.conf;
         location ~ /\.ht {
                deny all;

You may need to change the PHP rules if you’re using a different version, but aside from that, all you need to change is the server name. Now, enable the site:

sudo ln -s /etc/nginx/sites-available/phpmyadmin.conf /etc/nginx/sites-enabled

Check the config:

nginx -t

and restart NGINX:

sudo service nginx restart

Using phpMyAdmin

You should now be able to go to the subdomain you configured, and be able to sign into phpmyadmin with any MySQL user. Preferably, sign in with a root MySQL user, so you don’t need to change users for each database you want to modify. However, if you’re using PHP 7, you’ll notice a ton of deprecation errors, which will follow you around. The solution is to disable php-fpm error reporting, which can be done by adding:

error_reporting = off    

to /etc/php/7.0/fpm/php.ini. Remove any other uncommented lines for error_reporting if you want this to work. After reloading php, you should not see any errors!

You know have phpMyAdmin working with NGINX!


If you have Cloudflare, you might want to add a page rule to disable all caching, and increase the security level to maximum so bots can’t brute-force their way in to your database. Although, you should have nothing to fear because you have off-site DB backups :) .