How to Set Up and Secure PhpMyAdmin with Apache on Ubuntu 16.04


Step 1: Verifying the Installation of LAMP Stack

Apache Web Server

$ service apache2 status | grep active
Active: active (running) since Tue 2018-10-23 00:49:19 EAT; 10h ago
Active: inactive (dead)
$ sudo apt-get update 
$ sudo apt-get install apache2

Verifying Installation of MySQL Database Server

$ service mysql status | grep active
Active: active (running) since Sun 2018-10-21 10:24:44 UTC; 1 day 21h ago
Active: inactive (dead)
$ sudo apt-get install mysql-server
$ sudo mysql_secure_installation
Enter password for root user: PASSWORD
Setup Validate password Plugin: Y
Password validation policy level: 2
Change password for root: N (unless you want to change the password)
Remove anonymous users: Y
Disallow remote root login: Y
Remove test database: Y
Reload privileges table: Y

Verifying Installation of PHP Scripting Language

$ php -v
PHP 7.0.32-0ubuntu0.16.04.1 (cli) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.0.32-0ubuntu0.16.04.1, Copyright (c) 1999-2017, by Zend Technologies
The program 'php' can be found in the following packages:
* php7.0-cli
* hhvm
Try: apt install <selected package>
$ sudo apt-get install php libapache2-mod-php

Installing PHP Modules

$ sudo apt-get install php-cli php-common php-mbstring php-gd php-intl php-xml php-mysql php-zip php-curl php-xmlrpc

Step 2: Configuring PHP File Upload Settings

$ sudo nano /etc/php/7.0/apache2/php.ini
$ sudo ls -a /etc/php
.  ..  7.0
upload_max_filesize =2M
upload_max_filesize =16M
$ sudo service apache2 restart

Step 3: Installing phpMyAdmin

$ sudo apt-get install phpmyadmin
$ sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf-available/phpmyadmin.conf
$ sudo a2enconf phpmyadmin.conf
$ sudo service apache2 restart

Step 4: Testing the phpMyAdmin Setup


Step 5: Securing phpMyAdmin

$ sudo nano /etc/apache2/conf-available/phpmyadmin.conf
<Directory /usr/share/phpmyadmin>
Options FollowSymLinks
DirectoryIndex index.php
AllowOverride All
$ sudo nano /usr/share/phpmyadmin/.htaccess
AuthType Basic
AuthName "This page is restricted"
AuthUserFile /etc/phpmyadmin/.htpasswd
Require valid-user
$ sudo htpasswd -c /etc/phpmyadmin/.htpasswd john
$ sudo htpasswd  /etc/phpmyadmin/.htpasswd doe
$ sudo systemctl restart apache2

Testing phpMyAdmin Apache Basic Authentication




Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store