phpMyAdmin is one of the popular open-source software, that is used to manage MySQL/MariaDB databases. In this tutorial, I am going to explain how to install phpMyAdmin on Ubuntu 20.04. Also, I will explain how you can secure phpMyAdmin by adding an extra layer of security to protect phpMyAdmin.
So, let’s dive in.
Install phpMyAdmin on Ubuntu[Step by Step]
To install phpMyAdmin on Ubuntu 20.04, I have taken an AWS EC2 instance with Ubuntu 20.04 AMI. Before installing phpMyAdmin, make sure that you have met the following prerequisites for the installation.
Prerequisites
- Ubuntu 20.04 and logged in user with sudo privileges.
- LAMP installed on Ubuntu.
phpMyAdmin Installation Steps
To install phpMyAdmin on Ubuntu 20.04 server, follow below steps
Step 1: Installing phpMyAdmin on Ubuntu
Open terminal to update and upgrade the Ubuntu packages to the latest version.
$ sudo apt update && sudo apt upgrade
Now, install phpMyAdmin from default Ubuntu repository by following command.
$ sudo apt install phpmyadmin
After running this command, an installer prompt will be shown. You have to choose the web server that should be automatically configured to run phpMyAdmin.
Press space bar on keyboard to select apache2. Then press Tab to go to ok. Now click Enter to proceed.
Select Yes and press Enter to use dbconfig-common for setting up the database.
Now set password to connect the database with phpMyAdmin.
You need to confirm your password. Re-enter the password again and press Tab and Enter on the keyboard.
Once installation completed, restart Apache by following command for changes to take effect.
$ sudo systemctl restart apache2
Step 2: Adjust Authentication and Privileges for phpMyAdmin
When you installed phpMyAdmin onto your Ubuntu server, it automatically created a database user called phpmyadmin. It is recommended to use root instead of phpmyadmin user.
Configure password for root user
In Ubuntu server MySQL version 5.7 or later version, the root MySQL user is set to authenticate using the auth_socket
plugin by default rather than with a password.
To access phpMyAdmin as your root MySQL user, you will need to switch its authentication method from auth_socket to one that makes use of a password.
To do this, open up the MySQL prompt from your terminal
$ sudo mysql
Now, check the authentication method, by following command.
mysql> SELECT user,authentication_string,plugin,host FROM mysql.user;
+------------------+------------------------------------------------------------------------+-----------------------+-----------+
| user | authentication_string | plugin | host |
+------------------+------------------------------------------------------------------------+-----------------------+-----------+
| debian-sys-maint | $A$005$ktHnp7_`CgS.LxIaFEB1P2zjE.O3EptCEyPqlUbOPXeLoGIcr.5DGTp4 | caching_sha2_password | localhost |
| mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password | localhost |
| mysql.session | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password | localhost |
| mysql.sys | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password | localhost |
| phpmyadmin | $A$005$BPr6UabZ17dlvVCcxxby0/UWj/VeIyqbc87Qza0j3qiZY8FH5lMuYdy. | caching_sha2_password | localhost |
| root | | auth_socket | localhost |
+------------------+------------------------------------------------------------------------+-----------------------+-----------+
6 rows in set (0.00 sec)
Here, you can see that the root user does in fact authenticate using the auth_socket plugin. To configure the root account to authenticate with a password, run the following command.
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'your_password';
your password is set with root. Now check again to make sure root is using password instead of auth_socket.
mysql> SELECT user,authentication_string,plugin,host FROM mysql.user;
+------------------+------------------------------------------------------------------------+-----------------------+-----------+
| user | authentication_string | plugin | host |
+------------------+------------------------------------------------------------------------+-----------------------+-----------+
| debian-sys-maint | $A$005$ktHnp7_`CgS.LxIaFEB1P2zjE.O3EptCEyPqlUbOPXeLoGIcr.5DGTp4 | caching_sha2_password | localhost |
| mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password | localhost |
| mysql.session | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password | localhost |
| mysql.sys | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password | localhost |
| phpmyadmin | $A$005$BPr6UabZ17dlvVCcxxby0/UWj/VeIyqbc87Qza0j3qiZY8FH5lMuYdy. | caching_sha2_password | localhost |
| root | $A$005$-CZ0S Ag-/7A*rx4b3GdSEFyLfY2E4tHLDaV1eWT16uKoPzwHVLrci8E/ | caching_sha2_password | localhost |
+------------------+------------------------------------------------------------------------+-----------------------+-----------+
6 rows in set (0.00 sec)
Create a new MySQL User
You can create a dedicated MySQL user. To create MySQL user, open login to mysql again.
$ mysql -u root -p
You can give root password directly with command, but it is not recommended. So, after running the above command, it will ask for the root password. Now type root password and press Enter.
Now, run following command to create a new user in MySQL.
mysql> CREATE USER 'mysql_user_name'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'your_password';
Replace mysql_user_name by your user name and your_password by your desired password.
After creating new user, grant all the root privileges to the user. Rin following command to grant permission.
mysql> GRANT ALL PRIVILEGES ON *.* TO 'mysql_user_name'@'localhost' WITH GRANT OPTION;
Now, you can exit from MySQL command line by typing following command.
mysql> exit;
Step 3: Check phpMyAdmin installation
Check your phpMyAdmin installation on browser.
http://your_domain_name_or_IP/phpmyadmin
You should see something like this.
Conclusion
In this article, you have learned to install phpMyAdmin on Ubuntu. Follow this article thoroughly to install quickly. If you have any doubts feel free to contact me, I will definitely try to help you. Also, you can join our elite Facebook group to get direct help from me. If you like this tutorial, please share this article on your social media handle.