How to Install phpMyAdmin with Nginx on Ubuntu Server?

The phpMyAdmin is an open-source PHP-based tool for handle MySQL and MariaDB databases over a web-based interface.
phpMyAdmin permits you to connect with MySQL/MariaDB databases, manage user accounts and privileges, execute SQL-queries, import and export databases, and significantly more.
This article depicts how to install phpMyAdmin with Nginx on an Ubuntu server.
Prerequisites
Make sure that you have met the following requirements prior to proceeding with this article:
LEMP (Linux, Nginx, MySQL, and PHP 7) introduced on your Ubuntu worker.
Signed in as a user with sudo privileges.
Installing phpMyAdmin on Ubuntu
Installing phpMyAdmin is a genuinely easy task. Start by updating the Ubuntu packages list. Then, run the phpMyAdmin installation command to install it:
sudo apt update
sudo apt install phpmyadminEnsure you have Nginx and PHP FPM installed on your system before installing phpMyAdmin.
The installer will ask you to pick the web-server that should be automatically configured to run phpMyAdmin. But there is no option to pick Nginx. It's ok, don't select anything, press TAB to choose OK, and afterward press Enter. We'll configure Nginx in the next section.

Next, the installer will ask you if you want to use the 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.

Now phpMyAdmin has been installed on your Ubuntu server.
Create an Administrative MySQL User
In the Ubuntu server running MySQL, the root user is set to use the auth_socket authentication method by default.
The auth_socket module authenticates users that connect from the localhost through the Unix socket file. This implies that you can't authenticate as a root by giving a password.
Rather than changing the authentication method for the MySQL user root, we will make another administrative MySQL user. This user will have similar privileges as the root user and will be set to utilize the mysql_native_password authentication method.
For that, first, sign in to the MySQL server as the root user:
sudo mysqlFrom inside the MySQL shell execute the following commands which will create another administrative user and grant appropriate authorizations:
CREATE USER 'username'@'localhost' IDENTIFIED BY 'change-with-your-secure-password';
GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost' WITH GRANT OPTION;In this example, we named the administrative user username. You can use any name you like.
Configuring Nginx and phpMyAdmin
There are several ways how to configure the Nginx to serve phpMyAdmin files. We will create a snippet that we can include in any of our Nginx server block files.
So, in your editor of choice create /etc/nginx/snippets/phpmyadmin.conf file. Here I am going to use vi :
sudo vi /etc/nginx/snippets/phpmyadmin.confPaste 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/;
}
}Ensure you are using the right 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 your domain’s server block where you want to access phpMyAdmin using: domain.com/phpmyadmin
server {
# . . . other code
include snippets/phpmyadmin.conf;
# . . . other code
}Accessing phpMyAdmin
To get to the phpMyAdmin interface open your browser and type your server’s domain name or public IP address followed by /phpmyadmin:
http(s)://your_domain_or_ip_address/phpmyadminEnter the administrative user login credentials and click Go.

Conclusion
Congrats, you have effectively installed phpMyAdmin on your Ubuntu server. You would now be able to begin making MySQL databases, and tables and perform different MySQL queries and operations.
Please login or create new account to add your comment.