How to install phpMyAdmin with Nginx, MariaDB, PHP7 on Ubuntu 16.04

The database management tool phpMyAdmin is a free and open-source web-based written in PHP. It provides a graphical web interface for users to manage MySQL or MariaDB database.

Prerequisites

It is assumed that you have already installed LEMP stack on Ubuntu 16.04. If not, please check out the following tutorial.

With that out of the way, let’s get started with installation.

Step 1: Download and Install phpMyAdmin

phpMyAdmin is included in Ubuntu 16.04 software repository, so we can easily install it with the command below

sudo apt update
sudo apt install phpmyadmin

During the installation, it will prompt you to select a web server to configure. Nginx is not in the list, so press the Tab key and hit OK to skip this step.
 

install-phpmyadmin
 

Next, select Yes to create a new database.

 

phpmyadmin-install
 

This will also create a new database user named phpmyadmin. Give this user a password.

 

phpmyadmin-password
 

Once done, a new database named phpmyadmin is created and the database user phpmyadmin has necessary privileges to manage this database.

Step 2: Configure Nginx

To be able to access the phpMyAdmin web interface, we need to configure Nginx.  We will configure Nginx so that phpMyAdmin is a sub-directory of the existing website. Open your existing server block file of your website.

sudo nano /etc/nginx/conf.d/your-site.conf

Add the following lines in the server section.

location /phpmyadmin {
  root /usr/share/;
  index index.php;
  try_files $uri $uri/ =404;

  location ~ ^/phpmyadmin/(doc|sql|setup)/ {
    deny all;
  }

  location ~ /phpmyadmin/(.+\.php)$ {
    fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    include snippets/fastcgi-php.conf;
  }
 }

Your phpMyAdmin files are in /usr/share/phpmyadmin/ directory. The above configuration tells Nginx that if visitors enter your-domain.com/phpmyadmin in browser address bar, then find index.php file in /usr/share/phpmyadmin/ directory and display the web page.

Save and close the file. Then test configuration and reload.

sudo nginx -t
sudo systemctl reload nginx

Now you should be able to access phpMyAdmin web interface via your-domain.com/phpmyadmin/

Login with MariaDB root user and password.
 
phpmyadmin-login
 
The advantage of accessing phpMyAdmin from sub-directory rather than sub-domain is that if you have HTTPS enable on your main domain name, then you don’t have to install new TLS certificate to secure phpMyAdmin.
 
phpmyadmin-dashboard
 
In case you find any login issues you may need to Fix MariaDB Plugin ‘unix_socket’, please click on link below to find how to do it.
 

How to Fix MariaDB Plugin unix_socket, login error

ABOUT AUTHOR

Nuno

I am a Freelance Web Developer and WordPress Expert based in London with a wealth of website development and support experience. I am great at problem solving and developing quick solutions.

LEAVE A COMMENT

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  • LET'S TALK!

    Fill in the form below to make an enquiry or find my contact details on my contact page.

  • This form collects your name and email address so that I can respond to the enquiry(ies) that you submit via this website. Please check my privacy policy for the full story on how I use, protect and manage your submitted data.