Prerequisites
Ensure you are logged in as a non-root user with sudo privileges. Additionally, a LAMP (Linux, Apache, MySQL, PHP) stack must be active on your Ubuntu 14.04 server before proceeding.
Step 1: Installing the Tool
Begin by refreshing your local package index and installing the phpmyadmin package directly from the Ubuntu repositories:
sudo apt-get update
sudo apt-get install phpmyadmin
Follow the interactive prompts during installation:
- Select apache2 as the web server configuration.
- Choose yes when asked to use
dbconfig-commonto configure the database. - Enter your MySQL administrator password.
- Set and confirm a specific password for the phpMyAdmin application user.
The installer automatically places a configuration file in /etc/apache2/conf-enabled/. To ensure all features work, enable the mcrypt extension and restart the web service:
sudo php5enmod mcrypt
sudo service apache2 restart
You can now access the interface by navigating to your server's IP or domain:
http://your_server_ip_or_domain/phpmyadmin
Log in using the root username and the administrative password you configured for MySQL.
Step 2: Hardening the Installation
Since phpMyAdmin is a common target for bots and attackers, adding an extra layer of authentication is highly recommended. We will configure Apache to require a password before the phpMyAdmin login page is even displayed.
Enable .htaccess Overrides
Edit the phpMyAdmin Apache configuration file to allow directive overrides:
sudo nano /etc/apache2/conf-available/phpmyadmin.conf
Locate the <Directory /usr/share/phpmyadmin> section and add AllowOverride All:
<Directory /usr/share/phpmyadmin>
Options FollowSymLinks
DirectoryIndex index.php
AllowOverride All
...
</Directory>
Save the file and reload Apache:
sudo service apache2 restart
Create the .htaccess Policy
Create an .htaccess file within the application directory:
sudo nano /usr/share/phpmyadmin/.htaccess
Insert the following content to enforce Basic Authentication:
AuthType Basic
AuthName "Admin Area"
AuthUserFile /etc/phpmyadmin/.htpasswd
Require valid-user
This configuration tells Apache to check the credentials stored in /etc/phpmyadmin/.htpasswd and deny access to anyone who isn't a valid user.
Generate the Password File
You need the apache2-utils package to create the password file:
sudo apt-get install apache2-utils
Use the htpasswd command to create the file and add your first user (e.g., webadmin):
sudo htpasswd -c /etc/phpmyadmin/.htpasswd webadmin
You will be prompted to define a password for this user. To add more users later, omit the -c flag to avoid overwriting the file.
Now, when you visit the phpMyAdmin URL, the browser will prompt you for the credentials you just created before loading the databasee login screan.