Linux MySQL

Install phpMyAdmin on Ubuntu 20.04 with Nginx

Disclosure: This post may contain affiliate links, which means we may receive a commission if you click a link and purchase something that we recommended.

phpMyAdmin is a web-based application for interacting with MySQL database server. This tool provides you with a user interface to make MySQL operations so you don’t have to use the command line interface.

In this guide you are going to learn how to install phpMyAdmin with Nginx on Ubuntu.20.04 and secure it.

Prerequisites

Make sure you have LEMP setup in your server with Nginx, PHP and MySQL/MariaDB. If you don’t have the server setup you can follow the below guide to setup.
How to Install LEMP Nginx, MySQL, PHP in Ubuntu 20.04

Also setup server blocks to server PHP application.

Install phpMyAdmin

Once you have Nginx, PHP, MySQL installed you can start installing phpMyAdmin.

There are different ways to install phpMyAdmin, here we will follow the easiest way to install it.

Execute the below command to install phpMyAdmin.

sudo apt install phpmyadmin

In the prompt to choose web server, press TAB to skip this.

When prompted again to allow dbconfig-common to install a database and configure select Yes and press ENTER.

Then type and confirm a password or allow to use any random password.

Configure phpMyAdmin with Nginx

Once phpMyAdmin is installed you can configure it with Nginx so you can access the web interface.

There are several ways to accomplish this, you can just create a symbolic link of /usr/share/phpmyadmin directory to your web root.

Here we will learn now to create a new configuration for phpMyAdmin.

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

Add the following to the new file. Make sure you use the correct PHP version.

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/php8.0-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/;
    }
}

Save the file and exit.

Include the new file inside your server block from where you wish to access phpMyAdmin.

Edit your server block configuration which will be located inside /etc/nginx/sites-available and include the snippet so your configuration looks something similar to the one below.

server {
    . . .

    include snippets/phpmyadmin.conf;

    . . .
}

Restart Nginx for the changes to take effect.

sudo service nginx restart

Now you can access phpMyAdmin using your domain followed by /phpmyadmin.

https://domain.com/phpmyadmin

Conclusion

Now you have learned how to install phpMyAdmin on Ubuntu 20.04 with Nginx.

Thanks for your time. If you face any problem or any feedback, please leave a comment below.

2 Comments

  1. Arvind Kumar Reply

    I cannot explain how oblidged I am feeling after going through your post and give it another chance before I pull my hair apart. I have been trying for 4 hours and struggled with 403 forbidden errors for all media files including css,js and images and what I was missing was probably:

    location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
    root /usr/share/;
    }

    There are very poor posts about installing phpmyadmin on nginx without installing mysql and your post did the trick. Thank you soooo much!!

Write A Comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.