phpMyAdmin allows you to interact with MySQL databases, manage user accounts and privileges, execute SQL-statements, import and export  data in a variety of data formats and much more.

This tutorial describes how to install phpMyAdmin with Nginx on Ubuntu 18.04.

Prerequisites

Ensure that you have met the following prerequisites before continuing with this tutorial:

LEMP (Linux, Nginx, MySQL, and PHP 7) installed on your Ubuntu server. Logged in as a user with sudo privileges.

Although not necessary, it is highly recommended to access your phpMyAdmin instance over HTTPS. If you don’t have SSL enabled on your  sites.

Installing phpMyAdmin on Ubuntu

Installing phpMyAdmin is a fairly simple task. Start by updating the packages list:

sudo apt update

Next, run the following command to install the phpMyAdmin package from the default Ubuntu repositories:

sudo apt install phpmyadmin

Make sure you have Nginx and PHP FPM installed on your system before installing phpMyAdmin.

The installer will ask you choose the web server that should be automatically configured to run phpMyAdmin. There is no option to choose  Nginx, press TAB to

select OK and then Enter. We’ll configure Nginx in  the next section.

Next, the installer will ask you whether you want to use dbconfig-common tool to set up the database. Select Yes and hit Enter

Enter a password for phpMyAdmin to register with the database, select OK and press Enter.

You will be prompted to confirm the password, enter the same password, select OK and press Enter.

At this point phpMyAdmin has been installed on your Ubuntu server.

Nginx Snippet

In this guide we will create a snippet which we can include in any of our Nginx server block files. Open your text editor and create the following file:

sudo vim /etc/nginx/snippets/phpmyadmin.conf

Paste the following content:

location /phpmyadmin {
   root /usr/share/;
   index index.php index.html index.htm;
   location ~ ^/phpmyadmin/(.+.php)$ {
       try_files $uri =404;
       root /usr/share/;
       fastcgi_pass unix:/run/php/php7.2-fpm.sock;
       fastcgi_index index.php;
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
       include /etc/nginx/fastcgi_params;
   }

   location ~* ^/phpmyadmin/(.+.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
       root /usr/share/;
   }
}

Make sure you are using the correct socket path or address/port for the

fastcgi_pass directive. Save the file and close your editor.

You can now add the following line to each domain’s server block where you want to access phpMyAdmin using: domain.com/phpmyadmin

include snippets/phpmyadmin.conf;

Here is an example:

server {

   # . . . other code

   include snippets/phpMyAdmin.conf;

   # . . . other code 

}

Accessing phpMyAdmin

To access the phpMyAdmin interface open your favorite browser and type  your server’s domain name or public IP address followed by /phpmyadmin:

http(s)://your_domain_or_ip_address/phpmyadmin

Congratulations, you have successfully installed phpMyAdmin on your server.