Atlantic.Net Blog

How to Install and Secure phpMyAdmin in Ubuntu 14.04

Verified and Tested 01/31/2015

Introduction

This document will help you install phpMyAdmin and describe some basic steps to take in order to secure it.

Prerequisites

You need an Ubuntu 14.04 server that is configured with a static IP address.

You will also need to have LAMP (Linux, Apache, MySQL and PHP) installed on the server.

Installing phpMyAdmin

Install phpMyAdmin

sudo apt-get install phpmyadmin

phpMyAdmin is now installed on your server. Now we begin the Apache configuration.

 

Setup phpMyAdmin under Apache, edit the apache2.conf file.

sudo nano /etc/apache2/apache2.conf

Add the following code to the bottom of the apache2.conf file.

Include /etc/phpmyadmin/apache.conf
Add your config file for phpmyadmin

apache2.conf

Save your changes by pressing Ctrl + X then Y to accept.

Restart Apache.

sudo service apache2 restart

Verify that your installation works, type the following link in your browser http://YOURIP/myphpadmin

(Log in with the username and password that was created during the installation)

Securing myPHPAdmin

Setup security for phpMyAdmin, edit the apache.conf file:

sudo nano /etc/phpmyadmin/apache.conf

Locate the <Directory /usr/share/phpmyadmin> and add the following rule under DirectoryIndex index.php

AllowOverride All

 

Add directive AllowOveride All to apache.conf

apache.conf

Save your changes by pressing Ctrl + X then Y to accept.

Create the .htaccess file that will handle the authentication.

sudo nano /usr/share/phpmyadmin/.htaccess

Paste the following text in the file:

AuthType Basic
AuthName "Restricted Files"
AuthUserFile /etc/apache2/.phpmyadmin.htpasswd
Require valid-user
Sample: .htacess

Sample: .htacess

Save your changes by pressing Ctrl + X then Y to accept.

Create a user and password that you would like to use for security access by pasting the following code. Then you will enter and re enter your password. (Note:Replace username with the actual user that you want to create. I will be using admin).

sudo htpasswd -c /etc/apache2/.phpmyadmin.htpasswd username

Restart Apache.

sudo service apache2 restart

Verify that everything works by typing the following link in your browser http://YOURIP/myphpadmin and typing your security username and password

Sample Login Prompt

Sample Login Prompt

Congratulations! You have just installed and secured phpMyAdmin on your server. Thank you for following along in this How-To and feel free to check back with us for any new updates.

Atlantic.Net

Since 1995, Atlantic.Net has been providing internet services to customers, including managed, cloud, and vps hosting.  In 20+ years of service, our solutions have been focused on providing the very best in web solutions to our valued customers!

Get a $250 Credit and Access to Our Free Tier!

Free Tier includes:
G3.2GB Cloud VPS a Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year