• Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate
TecNStuff
Menu
  • Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate

How to Install phpMyAdmin with Apache on Debian 9

Written by Admin, Updated On May 7, 2019
apache, debian, mariadb, mysql, php, phpmyadmin
How to Install and Secure phpMyAdmin with Apache on Debian 9

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. This guide will outlines how to install phpMyAdmin with Apache on Debian 9.

Using 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.

Prerequisites#

Before staring, make sure you have met following requirements:

  • You should logged in on Debian server as non-root user account with sudo privileges.
  • Ensure that LAMP (Linux, Apache, MySQL and PHP) stack is installed on your Debian machine.

It is highly recommend to access your phpMyAdmin installation over HTTPS connections to prevent from attacks. If your domain is not secure with an SSL/TLS certificate, you can follow this guide to secure your Apache with Let’s Encrypt on Debian 9.

Installing phpMyAdmin with Apache on Debian#

Here, we will install phpMyAdmin from default Debian repositories.

At First, you need to update package index and upgrade the system packages to the latest versions by typing:

sudo apt update
sudo apt upgrade

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

sudo apt install phpmyadmin php-mbstring php-gettext
Install phpMyAdmin with Apache on Debian 9

It will ask you few configuration options for phpMyAdmin. First, you will be ask to choose web server as following screenshot. Select Apache by click on OK button.

Configuring phpMyAdmin

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

password phpMyAdmin

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

Confirm Password phpMyAdmin

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

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

sudo phpenmod php-mbstring

Afterwards, restart Apache for your changes to take effect:

sudo systemctl restart apache2

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;

Accessing phpMyAdmin#

You can access the phpMyAdmin interface by open web browser and type your server’s public IP address or domain name followed by /phpmyadmin:

https://ip_address_or_your_domain/phpmyadmin
phpMyAdmin Login page

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, which will look something like this:

phpMyAdmin Dashboard

Securing 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
login box

Once you will enter basic authentication details then only you will be taken to the phpMyAdmin login page where you need to enter your MySQL administrative user login credentials.

Conclusion#

By this tutorial, finally you have successfully installed phpMyAdmin with Apache on Debian 9 system. If you have any questions or suggestions feel free to leave a comment below.

If our content helps you, please consider buying us a coffee

Thank you for your support.

Share On
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
 Previous Article How to Install MariaDB on Ubuntu 18.04
Next Article   How To Set Up Apache Virtual Hosts on Ubuntu 18.04

Related Posts

  • How to Install Php 8 on Debian 10

    How to Install PHP 8 on Debian 10

    January 2, 2021
  • How to Install Php 8 on Ubuntu 20.04

    How to Install PHP 8 on Ubuntu 20.04

    December 28, 2020
  • How to Install GIMP on Debian 10

    How to Install GIMP 2.10 on Debian 10

    December 27, 2020

Leave a Reply Cancel reply

Popular Posts

  • How to Install Python 3.9 on Debian 10
    How to Install Python 3.9 on Debian 10 December 25, 2020
  • How to Install Php 8 on Debian 10
    How to Install PHP 8 on Debian 10 January 2, 2021
  • How to Install Python 3.9 on CentOS 8
    How to Install Python 3.9 on CentOS 8 December 31, 2020
  • How to Install Php 8 on Ubuntu 20.04
    How to Install PHP 8 on Ubuntu 20.04 December 28, 2020
  • How to Install GIMP on Debian 10
    How to Install GIMP 2.10 on Debian 10 December 27, 2020
© 2020 TecNStuff All rights reserved. This website is using and storing cookies on your browser. By using this website you agree our Privacy Policy.  Follow us -  Twitter | Facebook