There is a new version of this tutorial available for Ubuntu 22.04 (Jammy Jellyfish).

How to Install phpMyAdmin with Nginx on Ubuntu 18.04 LTS

phpMyAdmin is a free and open-source web-based database management tool for MySQL. It is used to perform administration tasks such as creating, editing, or deleting databases, and managing users and permissions. Using phpMyAdmin, you can import data from CSV and SQL, and export data to various formats like, CSV, SQL, XML, and PDF.

In this tutorial, we will learn how to install phpMyAdmin with Nginx on Ubuntu 18.04 server.

Requirements

  • A server running Ubuntu 18.04.
  • A static IP address 192.168.0.111 to your server.
  • A non-root user with sudo privileges.

Getting Started

Before starting, you will need to update your system with the latest version. You can do this by running the following command:

sudo apt-get update -y
sudo apt-get upgrade -y

Once your system is updated, restart the system to apply the changes.

Install LEMP Server

First, you will need to install Nginx, MariaDB server, PHP and other PHP modules to your system. You can install all of them by running the following command:

sudo apt-get install nginx php7.2 php7.2-common php7.2-mysql php7.2-mbstring php7.2-fpm php7.2-cgi php7.2-common php-pear php-gettext mariadb-server -y

Once all the packages are installed, start Nginx and MariaDB service and enable them to start on boot time with the following command:

sudo systemctl start nginx
sudo systemctl start mariadb
sudo systemctl enable nginx
sudo systemctl enable mariadb

Install phpMyAdmin

By default, phpMyAdmin is available in the Ubuntu 18.04 default repository. You can install it by just running the following command:

sudo apt-get install phpmyadmin -y

During the installation, the installer will ask you to choose the web server as shown in the following page.

Configuring phpMyAdmin

Don't select any option, because we will use Nginx as a web server. So, click on the OK button. Next, you will be asked to setup the database as shown in the following page:

Database common setup

Click on the No button. You should see the following page:

MySQL application password

Now, provide a password for phpMyAdmin to register with the database and click on the Ok button. You will be asked to confirm the password again. Provide the same password and click on the Ok button to finish the installation.

Configure Database

First, log in to MariaDB shell with the following command:

sudo mysql

Next, create a new administrator user account and grant appropriate permissions with the following command:

MariaDB [(none)]> CREATE USER 'phpadmin'@'localhost' IDENTIFIED BY 'mypassword';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'phpadmin'@'localhost' WITH GRANT OPTION;

Replace the word 'mypassword' with a secure password of your choice. Now, exit from the MariaDB shell with the following command:

MariaDB [(none)]>EXIT;

Configure Nginx

Next, you will need to create an Nginx virtual host file. You can do this with the following command:

sudo nano /etc/nginx/sites-available/phpmyadmin.conf

Add the following lines:

server {
        listen 80 default_server;
        listen [::]:80 default_server;
        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.php index.html index.htm index.nginx-debian.html;

        server_name 192.168.0.111;

        location ~ \.php$ {
           include snippets/fastcgi-php.conf;
           fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
           fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
           include fastcgi_params;
       }
}

Save and close the file. Then, check the Nginx for any syntax error with the following command:

sudo nginx -t

If everything will be fine, you should see the following output:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Next, enable the phpmyadmin virtual host file and remove the default virtual host file with the following command:

sudo rm -rf /etc/nginx/sites-enabled/default
sudo ln -s /etc/nginx/sites-available/phpmyadmin.conf /etc/nginx/sites-enabled/

Next, restart Nginx service to apply the changes with the following command:

sudo systemctl restart nginx

Next, check the status of the Nginx with the following command:

sudo systemctl status nginx

You should see the following output:

? nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2019-01-15 11:10:29 UTC; 2min 0s ago
     Docs: man:nginx(8)
  Process: 14871 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=0/SUCCESS)
  Process: 14885 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
  Process: 14874 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
 Main PID: 14886 (nginx)
    Tasks: 2 (limit: 1113)
   CGroup: /system.slice/nginx.service
           ??14886 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
           ??14887 nginx: worker process

Jul 15 11:10:29 ubuntu1804 systemd[1]: Stopped A high performance web server and a reverse proxy server.
Jul 15 11:10:29 ubuntu1804 systemd[1]: Starting A high performance web server and a reverse proxy server...
Jul 15 11:10:29 ubuntu1804 systemd[1]: nginx.service: Failed to parse PID from file /run/nginx.pid: Invalid argument
Jul 15 11:10:29 ubuntu1804 systemd[1]: Started A high performance web server and a reverse proxy server.

Access phpMyAdmin

phpMyAdmin is now installed and configured, it's time to access phpMyAdmin web interface.

Open your web browser and type the URL http://192.168.0.111/phpmyadmin/. You will be redirected to the following page:

PHPMyAdmin Login

Now, provide your administrator username and password. Then, click on the Go button. You should see the phpMyAdmin default dashboard in the following page:

PHPMyAdmin on Ubuntu 18.04 LTS

Congratulation! you have successfully installed and configured phpMyAdmin to your Ubuntu 18.04 LTS server. You can now manage your MariaDB database through the phpMyAdmin web-based interface. Feel free to ask me if you have any questions.

Share this page:

2 Comment(s)