×


Install phpMyAdmin with Apache on Debian 9 - Step by Step Process ?

phpMyAdmin is an open source and free database management tool for MySQL with web interface. It's PHP based application to interact with MySQL and MariaDB easily.

phpMyAdmin was created so that users can interact with MariaDB through a web interface. 

Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform related phpMyAdmin queries.

In this context, we shall look into how to install phpMyAdmin with Apache on Debian 9.


More about phpMyAdmin ?

With phpMyAdmin tool you can manage MySQL databases. In addition, you can also manage user accounts and privileges, import and export data and execute SQL statements and much more. 

phpMyAdmin provides an advanced SQL editor which makes it easy to build and test complex SQL queries. 

It also allows you to manage Databases, Users, Data import and export, stored procedures and triggers, execute and edit queries, search database globally and much more.


How to Install phpMyAdmin on Debian ?

Before proceeding with this Installation procedure, ensure that meet the following requirements:


1. Install phpMyAdmin

Here, we will install phpMyAdmin from default Debian repositories.

i. To begin, you need to update package index and upgrade the system packages to the latest versions by typing:

$ sudo apt update
$ sudo apt upgrade

ii. Now install phpMyAdmin package along with required dependencies using below command :

$ sudo apt install phpmyadmin php-mbstring php-gettext

You will be prompted to answer a few configuration options for phpMyAdmin. 

iii. First, you will be ask to choose web server. Select Apache by click on OK button.

iv. Next, you will be ask to configure the database for phpMyAdmin. Select Yes and hit Enter key to continue.

v. Now enter password for phpMyAdmin to register with the database, select OK and press Enter.

vi. Again, confirm the password by entering same password and hit on OK button.

vii. Now you need to enable php-mbstring extension by typing below command:

$ sudo phpenmod php-mbstring

viii. Afterwards, restart Apache for your changes to take effect:

$ sudo systemctl restart apache2


2. Create MySQL User and Set Privileges

With the Debian systems, the root user of MySQL is set to use the unix_socket authentication method by default. So it will authenticates users through the Unix socket file. It means that you can't authenticate as a root by providing a password.

So it will not be good to change authentication method for the MySQL root user. Since phpMyAdmin requires users to authenticate with a password, so you will need to create a new administrative MySQL account in order to access the interface. This user will have the same privileges as the root user and will be set to use the mysql_native_password authentication method.

Now, we will use that user to login to phpMyAdmin and do further administrative tasks on our MySQL or MariaDB server.

You can login by below command:

$ sudo mysql

Next, execute below commands to create a new administrative user with strong password and grant appropriate permissions:

mysql> CREATE USER 'newadmin'@'localhost' IDENTIFIED BY 'STRONG-PASSWORD';
mysql> GRANT ALL PRIVILEGES ON . TO 'newadmin'@'localhost' WITH GRANT OPTION;


How to Access phpMyAdmin ?

You can access the phpMyAdmin interface by opening your web browser and typing your server's public IP address or domain name followed by /phpmyadmin:

https://ip_address_or_your_domain/phpmyadmin

Log in to the interface with the administrative username and password which you created on previous step and hit on Go button.

When you log in, you'll see the phpMyAdmin user interface.


How to Secure phpMyAdmin ?

To add an addition security layer we will make phpMyAdmin directory password protected by setting up a basic authentication.

At First, we will create a password file with user using the htpasswd tool that comes with the Apache package. We will store the .htpasswd file in /etc/phpmyadmin directory:

$ sudo htpasswd -c /etc/phpmyadmin/.htpasswd newadmin

Here, newadmin is administrative username which we created for access phpMyAdmin interface. You can choose any user name of your choice. Once you execute above command it will prompt you to enter password and confirm password as below:

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

Now we will configure Apache to password protect the phpMyAdmin directory and use the .htpasswd file. To do it open phpmyadmin.conf by typing :

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

Make changes as following:

<Directory /usr/share/phpmyadmin>
    Options  +FollowSymLinks +Multiviews +Indexes  # change this line
    DirectoryIndex index.php
    # Add new line start
    AllowOverride None
    AuthType basic
    AuthName "Authentication Required"
    AuthUserFile /etc/phpmyadmin/.htpasswd
    Require valid-user
    # Add new line end
    <IfModule mod_php5.c>
    ...

After that, Save and close the file. To take effect restart the Apache service by type:

$ sudo systemctl restart apache2

Now, when you access your phpMyAdmin subdirectory, you will be prompt for the additional account name and password that you just configured:

https://ip_address_or_your_domain/phpmyadmin

Here you will enter basic authentication details which will take you to the phpMyAdmin login page where you need to enter your MySQL administrative user login credentials.


[Need urgent assistance in fixing phpMyAdmin errors? We can help you. ]


Conclusion

This article covers step by step process to Install and Configure phpMyAdmin with Apache on Debian 9 system. The phpMyAdmin utility is a graphical database management tool. By installing phpMyAdmin, you no longer need to use a default command-line interface to manage your databases.


To install wget:

1. Access your terminal window, and update your software package lists using the following command:

$ sudo apt update

2. The wget utility allows you to download files directly from the terminal window. Enter the following command to install the wget tool:

$ sudo apt install wget -y


To install Apache on Debian:

1. Open a terminal window, and install Apache by entering the following command:

$ sudo apt install apache2 -y

2. Enter the following command to make sure the Apache service is running:

$ systemctl status apache2

In the output, you should see a green status that says active (running).


To Install PHP on Debian 10:

1. Install core PHP packages and Apache and MySQL plugins with the following command:

$ sudo apt install php php-cgi php-mysqli php-pear php-mbstring php-gettext libapache2-mod-php php-common php-phpseclib php-mysql -y

2. Once the installation process is complete, verify that PHP has been installed:

$ php --version

The system displays the current version of PHP, along with the date of the release.