YouTube Icon

Code Playground.

How to Install and Secure phpMyAdmin with Apache on Debian 9


How to Install and Secure phpMyAdmin with Apache on Debian 9

phpMyAdmin is a free, open-source PHP based application intended to rearrange the organization of MySQL and MariaDB workers over an electronic interface. 

phpMyAdmin permits you to oversee MySQL information bases, client records and advantages, execute SQL-proclamations, import and fare information in a wide assortment of information organizations and substantially more. 

This instructional exercise depicts the means needed to introduce and protect phpMyAdmin on Debian 9 with Apache web worker. 


Guarantee that you have met the accompanying prerequisites prior to continuing with this instructional exercise: 

Have LAMP (Linux, Apache, MySQL, and PHP) introduced on your Debian worker . 

Signed in as a client with sudo advantages . 

Albeit discretionary, it is prescribed to get to your phpMyAdmin establishment over HTTPS. On the off chance that your space isn't now ensured by a SSL you can follow this guide and secure your Apache with Let's Encrypt on Debian 9 . 

Installing phpMyAdmin

Play out the accompanying strides to introduce phpMyAdmin on Debian 9: 

Update the bundle record and redesign the framework bundles to the most recent forms: 

sudo apt update && sudo apt upgrade

Introduce the phpMyAdmin bundle from the default Debian archives by composing: 

sudo apt install phpmyadmin

The installer will ask you pick the web worker that should be naturally arranged to run phpMyAdmin, pick apache by squeezing Space and afterward Enter. 

designing phpmyadmin web worker 

Next, you will be found out if to utilize dbconfig-normal to set up the information base, select Yes and hit Enter. 

arranging phpmyadmin information base 

Enter a secret word for phpMyAdmin to enroll with the information base, select OK and press Enter. 

arranging phpmyadmin secret phrase 

Affirm the secret word, select OK and press Enter. 

designing phpmyadmin affirm secret key 

When the establishment cycle is done, restart Apache for changes to produce results: 

sudo systemctl restart apache2

Creating Administrative MySQL User

In Debian frameworks running MariaDB 10.1 (and later), the root client is set to utilize the auth_socket confirmation technique as a matter of course. 

The auth_socket module verifies clients that interface from the localhost through the Unix attachment document. This implies that you can't confirm as a root by giving a secret phrase. 

Rather than changing the confirmation strategy for the MySQL client root, we will make another regulatory MySQL client. This client will have similar advantages as the root client and will be set to utilize the mysql_native_password verification strategy. 

We will utilize this client to login to the phpMyAdmin dashboard and preform managerial undertakings on our MySQL or MariaDB worker. 

Start by sign in to the MySQL worker as the root client: 

sudo mysql

From inside the MySQL shell execute the accompanying orders which will make another managerial client and award suitable authorizations: 

CREATE USER 'padmin'@'localhost' IDENTIFIED BY 'super-strong-password';

We named the managerial client padmin. You can utilize any name you like, simply make certain to set a solid secret word. 

Accessing phpMyAdmin

To get to the phpMyAdmin interface open your number one program and type your worker's space name or public IP address followed by/phpmyadmin: 


Enter the authoritative client login accreditations you recently made and click Go. 

When you sign in, you'll see the phpMyAdmin dashboard, which will look something like this: 

Securing phpMyAdmin

To add an additional layer of security we will secret word ensure the phpMyAdmin registry by setting up a fundamental confirmation. 

First we will make a secret word record with clients utilizing the htpasswd instrument that accompanies the Apache bundle. We will store the .htpasswd record in/and so on/phpmyadmin index: 

sudo htpasswd -c /etc/phpmyadmin/.htpasswd padmin

In this model we are making a client named padmin. You can pick any username, it doesn't need to be same as the regulatory MySQL client. 

The order above will incite you to enter and affirm the client's secret word. 

New password:
Re-type new password:
Adding password for user padmin

On the off chance that you need to add an extra client, you can utilize a similar order without the - c banner: 

sudo htpasswd /etc/phpmyadmin/.htpasswd padmin2


The following stage is to design Apache to secret phrase secure the phpMyAdmin index and utilize the .htpasswd record. 

To do so open the phpmyadmin.conf record which was consequently made during the phpMyAdmin establishment: 

sudo nano /etc/apache2/conf-available/phpmyadmin.conf

What's more, alter/embed the accompanying lines featured in yellow: 


<Directory /usr/share/phpmyadmin>
    Options  +FollowSymLinks +Multiviews +Indexes  # edit this line
    DirectoryIndex index.php

    AllowOverride None
    AuthType basic
    AuthName "Authentication Required"
    AuthUserFile /etc/phpmyadmin/.htpasswd
    Require valid-user

    <IfModule mod_php5.c>

Spare and close the document and restart Apache for changes to produce results: 

sudo systemctl restart apache2

Presently, while getting to your phpMyAdmin, you will be provoked to enter the login qualifications of the client you recently made: 


In the wake of entering the fundamental validation, you'll be taken to the phpMyAdmin login page where you need to enter your MySQL authoritative client login qualifications. 

It is additionally a smart thought to change the/phpmyadmin assumed name to something more one of a kind and secure. 


Congrats, you have effectively introduced phpMyAdmin on your Debian 9 worker. You would now be able to begin making MySQL information bases, clients and tables and perform different MySQL questions and activities. 

On the off chance that you have questions, don't hesitate to leave a remark beneath.