How to Install phpMyAdmin with Nginx on Ubuntu Server?

Harish Kumar · · 3005 Views
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.


Make sure that you have met the following requirements prior to proceeding with this article:

  1. LEMP (Linux, Nginx, MySQL, and PHP 7) introduced on your Ubuntu worker. 

  2. 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 phpmyadmin

Ensure 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.

How to Install phpMyAdmin with Nginx on Ubuntu Server?

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.

How to Install phpMyAdmin with Nginx on Ubuntu Server?

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

How to Install phpMyAdmin with Nginx on Ubuntu Server?

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

How to Install phpMyAdmin with Nginx on Ubuntu Server?

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 mysql

From 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';

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.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/;

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:

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:


Enter the administrative user login credentials and click Go.

How to Install phpMyAdmin with Nginx on Ubuntu Server?


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.

You may also like:

Understanding Linux File Permissions and Ownership

Linux file permissions are a critical cornerstone in the architecture of Linux systems, serving as a fundamental aspect of their security model. They meticulously define who can (...)
Harish Kumar

Learn PHP Development from beginning.

PHP stance Hypertext Preprocessor, it's server-side scripting laungage and easy to use. PHP  also well  known for its speed, simplicity, flexibility features that have made it (...)
Programmer Desk

How To Install NVM (Node Version Manager) on Ubuntu System?

This tutorial will assist you with installing NVM on the Ubuntu machine. Additionally, allow you to install different node versions and other useful examples.
Harish Kumar

Install phpMyAdmin Manually with Nginx server on Ubuntu

In this guide, I will show you how to install and configure phpMyAdmin with Nginx, MySQL, and PHP8.0 (LEMP) on an Ubuntu system. phpMyAdmin is a free and open-source database (...)
Harish Kumar

Install Laravel Valet Linux+ development environment on Ubuntu System

The official Laravel Valet development environment is great if you are an Apple user. But there is no official Valet for Linux or Window system.
Harish Kumar

Install and Setup Oh-My-Zsh on Ubuntu System

In this post, I will show you how to install ZSH (Z-Shell). Then, we set up the oh-my-zsh framework for managing ZSH. We will likewise show you how to change the ZSH theme and (...)
Harish Kumar