How to Install PHPMyAdmin on Ubuntu?

656 0
How to Install PHPMyAdmin on Ubuntu

PHPMyAdmin is a web-based application that provides a Graphical User Interface (GUI) to MySQL database administration. PHPMyAdmin supports multiple MySQL servers and an easy MySQL command line client alternative. In this guide, Here is a step-by-step guide to PHPMyAdmin installation.


Before you get started with this guide, make sure you complete some basic steps.

I assume that you already have a LAMP (Linux, Apache, MySQL, and PHP) or LEMP (Linux, Nginx, MySQL, and PHP) configured on your Ubuntu 14.04 server. In case, if you do not have any of this configuration, then you can follow the following guides:

Once you are done, check hostname and Fully Qualified Domain Name (FQDN).

hostname -f

hostname: This command shows your hostname.
Hostname -f: This command shows your fully qualified domain name (FQDN).

1. Update your system

sudo apt-get update && sudo apt-get upgrade -y

2. Install the mcrypt PHP module

sudo apt-get install mcrypt

Now restart your Apache Server by executing the following command:

sudo service apache2 restart

To get started, install phpMyAdmin from the default repositories of Ubuntu. To pull down the required files and proceed with installation, the apt packaging system can be used:

sudo apt-get install phpmyadmin

You will be asked for the server for which you want phpMyAdmin automatically configure. Select the installed web server on your Ubuntu. If you have multiple web server installed, you can choose the best-suited web server as per your need and deployment. After that, you can follow through the rest of the steps to set passwords.

Create a symbolic link from root to PHPMyAdmin directory for each virtual hosts to give access to your PHPMyAdmin installation:

cd /var/www/
sudo ln -s /usr/share/phpmyadmin

Alternatively, you can do it by running single line command as well. Both mean the same:

sudo ln -s /usr/share/phpmyadmin /var/www/

It will create a symbolic link named PHPMyAdmin in the root document.

As we know that mcrypt is a PHP module on which phpMyAdmin relies on. So we need to enable the mcrypt by restarting the PHP processor using the command below.

sudo php5enmod mcrypt
sudo service php5-fpm restart

Now phpMyAdmin is operational. For phpMyAdmin interface access, enter the server’s IP address or domain name followed by /PHPMyAdmin, in a web browser:


Step 2: Securing phpMyAdmin

1. .htaccess File

Now we need secure phpMyAdmin by using .htaccess file. This will allow specified IP addresses to access it. It can be done by creating a .htaccess file inside PHPMyAdmin directory.

order allow,deny
allow from

2. Force SSL

You can use your phpMyAdmin to use SSL in phpMyAdmin configuration file, which is present inside /etc/phpmyadmin/ directory. You can add the following line under the Server(s) configuration section:

$cfg['ForceSSL'] = 'true';

3. Changing the Application’s Access Location

Now, we need to rename the symbolic link to change the access location of the application from where PHPMyAdmin graphical user interface (GUI) can be accessed.

To know what exactly we are doing, let’s navigate to the Nginx document root directory:

cd /var/www/
ls -l

The output goes something like this:

total 188
-rw-r--r--  1 www-data www-data   418  Apr 18 15:37 index.php
-rw-r--r--  1 www-data www-data 19935 Apr 18 15:37 license.txt
lrwxrwxrwx 1 root root  18 Apr  6 15:37 phpmyadmin -> /usr/share/phpmyadmin

If we look at line 4, we can clearly identify that we have a symbolic link i.e, PHPMyAdmin in this directory. We can change this symbolic link to some other name or location that we would like to. This will change the access location of PHPMyAdmin. To do that let’s pick a new name for our symbolic link. Let’s call it “anonymous”. To create a symbolic link with this name, run the following command:

sudo mv phpmyadmin anonymous

Once you are done, run the following command:

ls -l

Now, you will notice that the symbolic link name has changed:

total 188
-rw-r--r--  1 www-data www-data   418  Apr 18 15:40 index.php
-rw-r--r--  1 www-data www-data 19935 Apr 18 15:40 license.txt
lrwxrwxrwx 1 root root  18 Apr  6 15:40 anonymous -> /usr/share/phpmyadmin

Now, if try to navigate to the previous phpMyAdmin directory location, you will get a 404 error:


However, your phpMyAdmin will be accessible at the new location:


4. Web Server Authentication Gate Setup

Web server authentication gate is a feature that enables authentication. Prompt that a user would be required to pass even before seeing the phpMyAdmin login screen.

In most of the web servers, this capability is natively available which includes Nginx as well. We just require modifying the configuration file of Nginx web server.

Before we do this, we need to create a password file that will store the web server authentication gate credentials. Nginx needs that passwords in encrypted form using the crypt() function. OpenSSL suite, which is already installed on your server, includes this functionality.
So, to create an encrypted password, run the following command:

openssl passwd

Now, you will be asked to enter the password that you need to confirm to use. Once you are done, you will be displayed an encrypted version of the password that will look like something  this:


Copy this encrypted password in a notepad. Later, we would require this password while creating web server authentication gate credential file.

Now, create web server authentication gate credential file. We will call this file pma_pass and we need to save it inside the Nginx configuration directory:

sudo vim /etc/nginx/pma_pass

Now we need to specify the username and followed by a colon (:), followed by the encrypted version of the password that we generated during encrypted password creation process using the openssl passwd.

Let’s say we have chosen a username “webmaster”, then it goes like this:


Save and close the file.

Now, we need to modify our Nginx configuration file.Open the Nginx configuration file for your website:

Open the Nginx configuration file for your website:

sudo vim /etc/nginx/sites-available/

Within the server block, inside file, add a new location. This will set the location for phpMyAdmin interface.

server {
. . .
location / {
try_files $uri $uri/ =404;

location /anonymous {

. . .

Within this block, set the value of a directive called auth_basic to an authentication message that the prompt will display.

In an, another directive called auth_basic_user_file, point web server to the authentication file that we created earlier.

After updating the configuration, the file should look like this:

server {
. . .
location / {
try_files $uri $uri/ =404;

location /anonymous {
auth_basic "Admin Login";
auth_basic_user_file /etc/nginx/pma_pass;
. . .

Now save and close the file.

Now check whether authentication gate is working or not. For that, we need to restart the web server:

sudo service nginx restart

Now, visit the phpMyAdmin location in your web browser. You are asked to enter the username and the password that you added earlier to the pma_pass file. Clear the browser cache and start a new session in case it does not ask for username and password.

Now enter the following web address in the browser by replacing the server_domain_or_IP with your IP address.


That’s it! You are done installing and securing phpMyAdmin on Ubuntu.

Hope you will find this useful. I would like to hear your views in the comment section below.

In this article

Join the Conversation