phpMyAdmin allows you to 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 which is much easier than via the command line.
This tutorial covers the steps required to install and secure phpMyAdmin with Apache on Ubuntu 18.04.
Make sure you have met the following prerequisites before continuing with this tutorial:
While not necessary, it is recommended to access your phpMyAdmin installation over 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 the package index and upgrade the system packages to the latest version:
$ sudo apt update && sudo apt upgrade
Install the phpMyAdmin package from the default Ubuntu repositories with the following command:
$ sudo apt install phpmyadmin
The installation will ask you to select a web server which should be configured automatically to run phpMyAdmin, select apache by pressing the button Space and then Enter.
Next, you will be asked whether to use
dbconfig-common To set up the database, select Yes and press Enter.
Enter the password or 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 your changes take effect:
$ sudo systemctl restart apache2
Create a MySQL Administrative User
In Ubuntu systems running MySQL 5.7 (and later), the root user is set to use the authentication method
auth_socket by default.
auth_socket authenticates users connected from localhost via a Unix socket file. This means that you cannot authenticate as root by providing a password.
Instead of changing the authentication method for the root MySQL user, I’m going to 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 login to the phpMyAdmin dashboard and perform previous administrative tasks on the MySQL or MariaDB server.
Start by logging into the MySQL server as the root user:
$ sudo mysql
From within the MySQL shell, run the following command which will create a new administrative user and grant 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, just make 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 followed by the url
Log in with the administrative user login credentials you created earlier and click on it Go.
After logging in, you will see the phpMyAdmin dashboard, which will look like this:
To add an extra layer of security, I’m going to password protect the phpMyAdmin directory by creating a basic authentication.
First we will create a password file with the user using the tool
htpasswd that comes with the Apache package. i will save the file
.htpasswd in the directory
$ sudo htpasswd -c /etc/phpmyadmin/.htpasswd padmin
In this example I created a user or a named user
padmin. You can choose any username, it doesn’t have to be the same as the MySQL administrative user name.
The command above will ask you to enter and confirm the user’s password.
Output New 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 mark
$ sudo htpasswd /etc/phpmyadmin/.htpasswd padmin2
The next step is to configure Apache to password protect the phpMyAdmin directory and use the
To do so, open the file
phpmyadmin.conf which 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 DirectoryIndex index.php AllowOverride None AuthType basic AuthName "Authentication Required" AuthUserFile /etc/phpmyadmin/.htpasswd Require valid-user ...
Save and Close files and Restart Apache so that your changes take effect immediately, type the following command:
$ sudo systemctl restart apache2
Now, when accessing your phpMyAdmin, you will be asked to enter the user login credentials you previously created:
After entering basic authentication, you will be taken to the phpMyAdmin login page where you will need to enter your MySQL administrative user login credentials.
It’s also a good idea to change aliases
/phpmyadmin into something more unique and safe.
Congratulations, you have successfully installed phpMyAdmin and secured phpMyAdmin with Apache on your Ubuntu 18.04 server. You can now start creating MySQL databases, users and database tables and perform various MySQL queries and operations through the web interface of phpMyAdmin.
Also read the following guide for installing LAMP on Ubuntu 18.04: