If you are not adept at managing your MySQL database on a terminal, phpMyAdmin provides a graphical interface that simplifies your database administration. phpMyAdmin is a free and open-source front-end PHP-based control panel that allows you to manage your MySQL databases & users, run complex queries, import and export database backups, review SQL activity, and adjust a myriad of other settings pertaining to your MySQL database. In this tutorial, you will learn how you can install phpMyAdmin on Ubuntu 18.04.
Prerequisites
Before we proceed to install phpMyAdmin, ensure you have the following installed.
- LAMP stack – Linux Apache MySQL PHP. You can follow steps in this tutorial to install LAMP stack on Ubuntu.
- MySQL 5.0.1 or later
- PHP 5.2.0 or later
To check MySQL version, log in to the MySQL database as shown.
1 |
# mysql -u root -p |
Provide and password, and thereafter, the details, including the version of MySQL, will be displayed
Output
To check the PHP version, execute the command.
1 |
# php -v |
Output
Install phpMyAdmin on Ubuntu 18.04
phpMyAdmin is available and kept up-to-date in Ubuntu’s repositories. This is therefore the recommended way of installing phpMyAdmin.
Step 1: Update the System
Firstly, update the system repositories using the command below
1 |
# sudo apt update -y |
Output
Step 2: Install and configure phpMyAdmin
To install phpMyAdmin, run the command
1 |
# sudo apt install phpMyAdmin -y |
Output
As the installation process proceeds, you will be presented with the screen below requiring you to choose the web server.
Hit on the SPACEBAR button to highlight ‘Apache‘.
Hit the TAB button which moves the cursor to the OK button
Next, hit ENTER.
The installation will continue for a few seconds and later bring you to this screen.
Select ‘Yes‘ and hit ENTER
The system will thereafter prompt you for the phpMyAdmin password. Provide the password.
Confirm the password in the next screen
After the installation is complete, you can find the phpMyAdmin configuration in the /etc/apache2/conf-enabled/phpmyadmin.conf
file
Finally, restart Apache web server to effect the changes
1 |
# systemctl restart apache2 |
Step 3: Accessing phpMyAdmin panel
To log in to phpMyAdmin, fire up your browser and browse your server’s URL as shown
https://server-ip/phpmyadmin/
Be sure to log in using the root user and corresponding password
Hit “Go” To access the phpMyAdmin dashboard
Securing phpMyAdmin
Before we wrap up this tutorial, we need to pay heed to some security considerations when using phpMyAdmin.
phpMyAdmin communicates directly with MySQL database and uses the same authentication credentials that are used when accessing MySQL. For these 2 reasons, phpMyAdmin becomes a potential target for hackers. Therefore, running phpMyAdmin over plain HTTP connection is advised against. One of the ways of securing our phpMyAdmin instance is by placing a gateway in front of the platform.
We will use Apache’s .htaccess for authorization and authentication.
Configure Apache to allow .htaccess overrides
To begin with, we are going to enable the .htaccess file overrides function by editing the Apache configuration file in /etc/apache2/conf-available/phpmyadmin.conf
.
We will add the AllowOverride All
directive in the section of the Apache configuration file as shown
1 2 3 4 5 6 |
Options FollowSymLinks DirectoryIndex index.php AllowOverride All . . . |
Save and exit the text editor.
To effect the changes, restart the Apache web server
1 |
# systemctl restart apache2 |
Create a .htaccess file
Having enabled the .htaccess
use for our phpMyAdmin application, let’s create the .htaccess
file for security implementation.
For it to be a success, we are going to create the file within phpMyAdmin directory
1 |
sudo vim /usr/share/phpmyadmin/.htaccess |
Add the following information to the file
1 2 3 4 5 6 7 |
/usr/share/phpmyadmin/.htaccess AuthType Basic AuthName "Restricted Files" AuthUserFile /etc/phpmyadmin/.htpasswd Require valid-user |
Let’s have a look at some of the terminologies in the file
AuthType Basic
: The attribute specifies the type of authentication to be implemented. This implements a password authentication using a password file.
AuthName
: This attribute sets the message for the authentication dialog box.
AuthUserFile
: This defines the location of the password file to be used for the authentication.
Require valid-user
: This attribute specifies that only authenticated users are allowed to access phpMyAdmin application. This keeps any unauthorized users from logging in.
Create a .htpasswd file for authentication
The final stage will be to create a .htpasswd
file for authentication. We are going to create it within the /etc/phpmyadmin/.htpasswd
file like we specified earlier in the /usr/share/phpmyadmin/.htaccess
file.
1 |
sudo htpasswd -c /usr/share/phpmyadmin/.htpasswd username |
Thereafter, you will be prompted to create a password and later confirm for the user that you are creating.
In the output below, we have created user ‘spikey‘
You can add an additional user without the -c
flag as shown
1 |
# sudo htpasswd /etc/phpmyadmin/.htpasswd additionaluser |
Now, let’s access phpMyAdmin via the browser. Notice the pop-up authentication dialog box.
Use the credentials you defined using the htpasswd
command and click on ‘Sign In’.
https://server-ip/phpmyadmin/
After logging in, you will be directed to the phpMyAdmin dashboard as before.
Wrapping up
This concludes our tutorial on how you can install phpMyAdmin on Ubuntu 18.04 with additional security. phpMyAdmin provides a seamless and efficient way of managing your databases, users and other aspects of your databases and tables.