Install and Secure phpMyAdmin On Ubuntu 20.04 / 19.10

We can install and secure PHPMyAdmin on ubuntu 20.04 as well as on ubuntu 18.04. we can handle the database server like MariaDB and MySQL with GUI. Let’s see, how to install and secure PHPMyAdmin on ubuntu.

Install and Secure phpMyAdmin On Ubuntu 20.04 / 19.10

We’ll update and upgrade the Ubuntu machine using the following commands. you don’t need to run those commands on Production servers. 

sudo apt update
sudo apt upgrade -y

Once you have updated the system, we need to install the PHPMyAdmin using the below commands. I’m assuming you’re using a non-root user with sudo permissions.

sudo apt install phpmyadmin php-mbstring php-gettext

If you’re not able to install the “php-gettext” package, you can simply use the below command to install “gettext” then you don’t need a “php-gettext” package.

sudo apt install gettext -y

During the installation, it will ask you for the webserver like “apache2 or Lighttpd“. I will select the “apache2” then Enter the “Space bar” and finally press “tab” and hit on “OK“. 

secure phpmyadmin ubuntu

Check Out: How To Secure and Hardening Apache Web Server On Ubuntu 20.04

After the installation, it needs to configure the Database for PHPMyAdmin with “dbconfig-common” then hit on “Yes“.  

phpmyadmin install ubuntu

Set MySQL application password for the PHPMyAdmin and click on “OK”

install phpmyadmin ubuntu 18.04

Again type the same password for the confirmation and click on “OK”

Install and Secure phpMyAdmin

Now we need to provide the administrator password for the “root” user. I have already installed MySQL version 8 on ubuntu 20.04. 

how to install phpmyadmin in ubuntu 20.04

Troubleshooting with Database:

In some cases, you will receive the database connection issue. So, simply remove the package using the following command. 

sudo apt autoremove phpmyadmin php-mbstring

Once the package is removed then again run the sudo apt install phpmyadmin php-mbstring command.

Check Out: How To Install KDE Plasma 5 On Debian/Ubuntu 20.04

After the dbconfig-common step, you will receive these windows prompt and I have selected the “localhost” because I’m running the database on the same machine then click on “OK“. you can also select the “new host” depends on your requirements.

how to create database in phpmyadmin ubuntu

Once the installation finished. we will enable the PHP extension using the below command. 

sudo phpenmod mbstring

We need to restart the apache service and hit the below URL in the browser to access the PHPMyAdmin. 

sudo systemctl restart apache2

URL: http://Your_IP/phpmyadmin/

Log in with your credentials username: phpmyadmin and password which you have created at the time of installation. 

In a similar way, we can install PHPMyAdmin on any ubuntu version like 18.04 / 19.10.

We can find the PHPMyAdmin configuration location at /etc/phpmyadmin/ and dbconfig location at /etc/dbconfig-common/. Suppose you’re running multiple websites on the same server and needs to enable the PHPMyAdmin.

Check Out: How To Install Themes on WordPress 5.4 On Linux

You will have to add the below line in the apache configuration file at /etc/apache2/apache2.conf. Open the file using any editor like nano or vim then add the below line. 

Include /etc/phpmyadmin/apache.conf

Now reload the apache service. 

sudo systemctl reload apache2

Securing PHPMyAdmin on Ubuntu 20.04:

We will add the extra layer of security on the PHPMyAdmin directory with the basic authentication method. you will need to create a password file with passwd tool that comes with an apache package and store it inside the /etc/phpmyadmin directory. 

ubuntu@ubuntu:$ sudo htpasswd -c /etc/phpmyadmin/.htpasswd phpadmin
New password: 
Re-type new password: 
Adding password for user phpadmin

If you require to create another user, use the same command without “-c” options.N

sudo htpasswd /etc/phpmyadmin/.htpasswd phpadmin2

Check Out:  How To Enable Instant Articles To Monetize Your Contents

Now we will have to tell the apache to use the password file. you need to open the phpmyadmin.conf file which is created automatically during the installation. 

sudo vim /etc/apache2/conf-available/phpmyadmin.conf

Edit or insert the below code and save the file. 

<Directory /usr/share/phpmyadmin>
## Options SymLinksIfOwnerMatch
Options +FollowSymLinks +Multiviews +Indexes 
DirectoryIndex index.php


AllowOverride None
AuthType basic
AuthName "Authentication Required"
AuthUserFile /etc/phpmyadmin/.htpasswd
Require valid-user

We need to restart the apache service then open the PHPMyAdmin in the browser. this should ask the username and password which you have created above using the htpasswd command. 

Once you have provided the details then click on “OK“. you will see the PHPMyAdmin login page and login with your database credentials.

That’s it.

Share on:

I'm the founder of Curious Viral. I hope this blog will provide you complete information about Linux Technology & I would like to share my technical knowledge with you which I have learned during this period.

Other Posts You May Like...

Leave a comment