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.

  1. LAMP stack – Linux Apache MySQL PHP. You can follow steps in this tutorial to install LAMP stack on Ubuntu.
  2. MySQL 5.0.1 or later
  3. PHP 5.2.0 or later

To check MySQL version, log in to the MySQL database as shown.

Copy
# mysql -u root -p

Provide and password, and thereafter, the details, including the version of MySQL, will be displayed

Output
Check Mysql Version

To check the PHP version, execute the command.

Copy
# php -v

Output

Check PHP Version

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

Copy
# sudo apt update -y

Output

Update System Repositories

Step 2: Install and configure phpMyAdmin

To install phpMyAdmin, run the command

Copy
# sudo apt install phpMyAdmin -y

Output

Install Phpmyadmin on Ubuntu 18.04

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.

Web Server To Reconfigure

The installation will continue for a few seconds and later bring you to this screen.

install  Phpmyadmin on Ubuntu 18.04

Select ‘Yes‘ and hit ENTER

The system will thereafter prompt you for the phpMyAdmin password. Provide the password.

provide MySQL Password

Confirm the password in the next screen

Password Confirmation MySQL

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

Copy
# 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

http://server-ip/phpmyadmin/

Be sure to log in using the root user and corresponding password

Phpmyadmin Login Page

Hit “Go” To access the phpMyAdmin dashboard

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

Copy
Options FollowSymLinks DirectoryIndex index.php AllowOverride All . . .

 AllowOverride attribute in .htaccess file

Save and exit the text editor.

To effect the changes, restart the Apache web server

Copy
# 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

Copy
sudo vim /usr/share/phpmyadmin/.htaccess

Add the following information to the file

Copy
/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.

Copy
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

Configure Htaccess Username And Password

You can add an additional user without the -c flag as shown

Copy
# 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’.

http://server-ip/phpmyadmin/

Sign In Using Htaccess File

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.