phpMyAdmin is an open-source PHP application designed to handle MySQL and MariaDB server administration through a web-based interface.
phpMyAdmin lets you manage databases, user accounts, and MySQL privileges, execute SQL statements, import and export data in various data formats and much more through a web-based interface that is much easier than through the command line.
This tutorial covers the steps needed to install and secure phpMyAdmin with Apache on Ubuntu 18.04.
Make sure you have fulfilled the following prerequisites before continuing with this tutorial:
- Have LAMP (Linux, Apache, MySQL, and PHP) already installed on your Ubuntu server.
- Log in as a user with sudo privileges. Read → How to Create a Sudo User and Sudo Group on Ubuntu
Although it is not necessary, it is recommended to access your phpMyAdmin installation via HTTPS. If your domain is not protected or secured with SSL, you can follow this guide and secure your Apache with Let’s Encrypt on Ubuntu 18.04.
How to Install phpMyAdmin on Ubuntu
To install phpMyAdmin on your Ubuntu 18.04 server, follow these steps:
Update package indexes and upgrade system packages to the latest versions:
$ sudo apt update && sudo apt upgrade
Install the phpMyAdmin package from the default Ubuntu repository with the following command:
$ sudo apt install phpmyadmin
The installation will ask you to choose a web server that must be configured automatically to run phpMyAdmin, select apache by pressing the Space key and then Enter.
Next, you will be asked whether to use
dbconfig-commonto manage the database, select Yes and press Enter.
Enter the password for phpMyAdmin, this is used to register with the database, select OK and press Enter.
You will be asked to confirm the password, enter the same password, select OK and press Enter .
After the installation process is complete, restart Apache so that the changes you make are applied:
$ sudo systemctl restart apache2
Create a MySQL Administrative User
In Ubuntu systems running MySQL 5.7 (and later), root users are set to use the authentication method
auth_socketauthenticates users who are connected from localhost via a Unix socket file. This means you cannot authenticate as root by providing a password.
Instead of changing the authentication method for the MySQL user root, I will create a new administrative MySQL user. This user will have the same rights as the root user and will be set to use the authentication method
I will use this user to log in to the phpMyAdmin dashboard and perform previous administrative tasks on the MySQL or MariaDB server.
Start by logging in to the MySQL server as the root user:
From within the MySQL shell, run the following command which will create a new administrative user and give the appropriate permissions:
mysql> CREATE USER 'padmin'@'localhost' IDENTIFIED BY 'super-strong-password';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'padmin'@'localhost' WITH GRANT OPTION;
In my example, I named the administrative user with
padmin. You can use whatever username you like, making sure to set a strong password.
To access the phpMyAdmin interface open your favorite browser and type your server’s domain name or public IP address and followed by the url
Log in with the administrative user login credentials that you created earlier and click Go .
After logging in, you will see the phpMyAdmin dashboard, which will look like this:
To add an additional layer of security, I will protect the phpMyAdmin directory password or password by making basic authentication.
First we will create a password file with the user using the tool
htpasswdthat came with the Apache package. I will save the file
.htpasswdin the directory
sudo htpasswd -c /etc/phpmyadmin/.htpasswd padmin
In this example, I created a user or named user
padmin. You can choose any username, it doesn’t have to be the same as the user name for administrative MySQL.
The above command will ask you to enter and confirm the user’s password.
Re-type new password:
Adding password for user padmin
If you want to add additional users, you can use the same command without the sign
$ sudo htpasswd /etc/phpmyadmin/.htpasswd padmin2
The next step is to configure Apache so that the password protects the phpMyAdmin directory and uses the file
To do this, open the file
phpmyadmin.confthat was automatically created during the phpMyAdmin installation:
sudo nano /etc/apache2/conf-available/phpmyadmin.conf
Please edit/enter the following lines:
Options +FollowSymLinks +Multiviews +Indexes # edit this line
AuthName "Authentication Required"
Save and Close file and Restart Apache so that the changes you make immediately apply, type the following command:
$ sudo systemctl restart apache2
Now, when accessing your phpMyAdmin, you will be asked to enter the user login credentials that you previously created:
After entering basic authentication, you will be taken to the phpMyAdmin login page where you must enter your MySQL administrative user login credentials.
It’s also a good idea to change aliases
/phpmyadminto something more unique and secure.
Congratulations, you have successfully installed phpMyAdmin and secured phpMyAdmin with Apache on your Ubuntu 18.04 server. You can now start creating MySQL databases, user and database tables and perform various MySQL requests and operations via the web interface of phpMyAdmin.