How to install phpMyAdmin with Nginx on Ubuntu 18.04

s2 0

phpMyAdmin is an open source PHP based tool for managing MySQL and MariaDB servers through a web-based interface.

With phpMyAdmin you can interact with MySQL databases, manage user accounts and permissions, 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.

requirements

Make sure you meet the following requirements before proceeding with this tutorial:

  • LEMP (Linux, Nginx, MySQL and PHP 7) installed on your Ubuntu server.

  • Logged in as a user with sudo permissions.

While not required, it is highly recommended that you access your phpMyAdmin instance via HTTPS. If you haven’t enabled SSL on your websites, check out our article on how to secure your Nginx with Let’s Encrypt on Ubuntu 18.04.

Install phpMyAdmin on Ubuntu

Installing phpMyAdmin is a pretty straightforward task. Start by updating the package 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 Nginx and PHP FPM are installed on your system before installing phpMyAdmin.

The installation program will ask you to select the web server that should be automatically configured to run phpMyAdmin. There is no option to select Nginx, press TAB to select OK and then Enter. We’ll configure Nginx in the next section.

Next, the installer will ask if you want to use dbconfig-common Tool for setting up the database. Choose Yes and hit Enter.

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

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

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

Create a MySQL administrative user

On Ubuntu systems running MySQL 5.7 (and higher), the root user is set to use the auth_socket Authentication method by default.

the auth_socket Plugin authenticates users who connect from localhost via the Unix socket file. This means that you cannot authenticate as root by providing a password.

Instead of changing the authentication method for the MySQL user root, we will create a new MySQL administrative user. This user has the same permissions as the root user and is set to have the mysql_native_password Authentication method.

We use this user to log into the phpMyAdmin dashboard and perform administrative tasks on our MySQL server.

First log in to the MySQL server as the root user:

sudo mysql

In the MySQL shell, run the following commands that will create a new administrative user and grant the appropriate permissions:

CREATE USER 'padmin'@'localhost' IDENTIFIED BY 'change-with-your-secure-password';GRANT ALL PRIVILEGES ON *.* TO 'padmin'@'localhost' WITH GRANT OPTION;

In this example we named the administrative user padmin. You can use any name you want, just make sure you set a strong password.

Configuring Nginx and phpMyAdmin

There are several ways to configure Nginx to serve phpMyAdmin files. If the server block of your domain is already set up to serve the PHP requests, you can simply create a symbolic link from the phpMyAdmin installation files to your domain documents root directory.

In this guide, we’re going to create a snippet that we can include in any of our Nginx server block files.

Open your text editor and create the following file:

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

Paste the following content:

/etc/nginx/snippets/phpmyadmin.conf
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 the server block of each domain with which you want to access phpMyAdmin: domain.com/phpmyadmin

include snippets/phpmyadmin.conf;

Here is an example:

/etc/nginx/conf.d/domain.com.conf
server {

    # . . . other code

    include snippets/phpmyadmin.conf;

    # . . . other code 

}

Access to phpMyAdmin

To access the phpMyAdmin interface, open your preferred browser and enter the domain name or public IP address of your server followed by /phpmyadmin:

http(s)://your_domain_or_ip_address/phpmyadmin

Enter the login credentials of the administrative user and click on Go.

Once you’re signed in, you’ll see the phpMyAdmin dashboard, which looks something like this:

diploma

Congratulations, you have successfully installed phpMyAdmin on your Ubuntu 18.04 server. You can now begin creating MySQL databases, users, and tables, and performing various MySQL queries and operations.

If you have any questions, feel free to leave a comment below.