How to Install and Secure phpMyAdmin on Debian 9

Introduction

phpMyAdmin is a free and open source web-based database management tool written in PHP. It is used to manage MySQL and MariaDB databases. It provides a graphical user interface to manage databases, create and modify tables, add, delete, or edit data, and perform other database operations. Installing and securing phpMyAdmin on Debian 9 is a straightforward process. This guide will walk you through the steps of installing and securing phpMyAdmin on Debian 9.

How to Install and Secure phpMyAdmin on Debian 9

1. Update the System

Before installing any packages on your Debian system, it is recommended to update the system packages to their latest version. You can do this by running the following command:

sudo apt-get update

2. Install phpMyAdmin

Once the system is updated, you can install phpMyAdmin by running the following command:

sudo apt-get install phpmyadmin

3. Configure Apache

Once the installation is complete, you need to configure Apache to use phpMyAdmin. To do this, you need to create a symbolic link between the phpMyAdmin directory and the Apache web root directory.

You can do this by running the following command:

sudo ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin

4. Configure phpMyAdmin

Once the symbolic link is created, you need to configure phpMyAdmin. To do this, you need to edit the phpMyAdmin configuration file.

You can do this by running the following command:

sudo nano /etc/phpmyadmin/config.inc.php

5. Secure phpMyAdmin

Once the configuration is complete, you need to secure phpMyAdmin. To do this, you need to create an .htaccess file in the phpMyAdmin directory.

You can do this by running the following command:

sudo nano /var/www/html/phpmyadmin/.htaccess

6. Restart Apache

Once the .htaccess file is created, you need to restart Apache for the changes to take effect. You can do this by running the following command:

sudo systemctl restart apache2

7. Test phpMyAdmin

Once Apache is restarted, you can test phpMyAdmin by opening your web browser and navigating to http://your_server_ip/phpmyadmin. You should be able to access the phpMyAdmin login page.

Introduction

phpMyAdmin is a software tool used for managing MySQL databases through a graphical interface. The tool can be configured to maintain a local database or a remote database over the network.

This software can replace the default command-line interface you use for database management.

In this article, you will learn how to install and secure phpMyAdmin on Debian 9.

how to install and secure phpmyadmin on debian9

Prerequisites

  • LAMP stack (Linux, Apache, MySQL, PHP) installed and configured on the server
  • Access to a user account with root privileges (ability to use the sudo command)
  • A Debian 9 operating system, configured for LAMP
    • The stack should include a database, which already has a root user
    • MySQL is a common choice, but MariaDB can also work
  • Access to a command prompt

Installing phpMyAdmin on Debian 9

Step 1: Refresh Latest Version of Software Packages

The software package for phpMyAdmin is part of the default software repositories. However, you still need to ensure you’re getting the latest version.

Refresh the repository index and upgrade the packages with the following command:

sudo apt update && sudo apt upgrade

Warning: Do not skip this step! Some of the older versions of phpMyAdmin had security flaws and could allow unauthorized users to access your database.

Step 2: Install phpMyAdmin

To install phpMyAdmin, enter:

sudo apt install phpmyadmin

The system runs through several automated steps and asks you for confirmation. Enter Y and give it a minute to complete. Once it finishes, a configuration screen loads.

Step 3: Configure phpMyAdmin

1. The first prompt asks you to choose which web server to reconfigure automatically. Make sure apache2 is selected, and click OK.

phpMyAdmin configuration window, selecting a web server.

Let the setup go through the process until the next step.

2. On the following screen, the wizard asks if you want to configure the database for phpmyadmin with dbconfig-common. Choose Yes as we will not deal with the advanced set up in this guide.

phpMyadmin configuration, selecting dbconfig-common

3. Next, enter a password for phpMyAdmin and confirm it. If you do not want to specify your password, leave the space blank to auto-generate one. You will use this password later to access phpMyAdmin.

Set password for phpMyAdmin

4. In the end, the installer requests your root password for the database. Provide the password and select OK.

5. Confirm phpMyAdmin is installed and that it contains a configuration. Navigate to the configuration file:

/etc/apache2/conf-enabled/phpmyadmin.conf

If you are an advanced user and you have any custom configurations to add, you can edit this file with your favorite text editor for linux.

Securing phpMyAdmin

The Alias is a line in the configuration file that specifies the web address used to access the application. Therefore, since many hackers and bots target the default configuration, it’s a good idea to change the alias.

1. First, open the phpmyadmin configuration file by entering:

sudo vim /etc/apache2/conf-enabled/phpmyadmin.conf

2. Search for the line that says:

Alias /phpmyadmin /usr/share/phpmyadmin

3. Flag this line as a comment by adding a # sign at the beginning:

# Alias /phpmyadmin /usr/share/phpmyadmin

4. Then, type a new line below it and change the alias, for example:

Alias /phpmyadmin /usr/share/MySecretLogin

5. Save the file and exit.

Refresh Apache Web Services

To refresh Apache web services, use the command:

sudo service apache2 restart

Access phpMyAdmin

Open a web browser and enter the IP address of your server, followed by the alias you configured earlier.

http://IP_ADDRESS_or_DOMAIN/MySecretLogin

If you did not change the alias, the default URL is:

http://IP_ADDRESS_or_DOMAIN/phpmyadmin

The webpage should display a login screen for phpMyAdmin.

phpMyAdmin Login Page

Enter the username and password for your database user, and you’ll be able to manage the database utilities from the graphical interface.

Conclusion

Now you have phpMyAdmin installed and configured on your Debian 9 server.

The phpMyAdmin software package takes a lot of the pain out of managing a database via the command line. Most database administrators consider it a staple of their installation.

How to Install and Secure phpMyAdmin on Debian 9

phpMyAdmin is a free and open source web-based database management tool written in PHP. It is used to manage MySQL and MariaDB databases. It provides a graphical user interface to manage databases, create and modify tables, add, delete and edit fields, execute SQL statements, manage users and permissions, and more. In this tutorial, we will show you how to install and secure phpMyAdmin on a Debian 9 server.

Prerequisites

Before you begin, you will need the following:

  • A Debian 9 server with a non-root user with sudo privileges.
  • A LAMP stack installed on your server.

Step 1 — Installing phpMyAdmin

The phpMyAdmin package is included in the default Debian 9 repositories. You can install it by running the following command:

sudo apt-get install phpmyadmin

During the installation, you will be asked to select the web server that should be automatically configured to run phpMyAdmin. Select apache2 by pressing the SPACEBAR and then TAB to select OK.

Next, you will be asked to configure the database for phpMyAdmin with dbconfig-common. You will be asked to provide the MySQL application password for the administrative user. This is the same password you provided during the LAMP stack installation.

Once the installation is complete, you can verify that phpMyAdmin is installed by visiting http://your_server_ip/phpmyadmin in your web browser.

Step 2 — Securing phpMyAdmin

By default, phpMyAdmin is accessible on the public internet. To secure it, we will configure Apache to allow access only from certain IP addresses. To do this, open the phpMyAdmin Apache configuration file:

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

Find the following line:

Allow from all

Replace it with the following, replacing 203.0.113.0/24 with your own IP address or network:

Allow from 203.0.113.0/24

Save and close the file. Then, enable the configuration by running the following command:

sudo a2enconf phpmyadmin

Finally, restart Apache for the changes to take effect:

sudo systemctl restart apache2

Now, phpMyAdmin will be accessible only from the IP address or network you specified.

Conclusion

In this tutorial, you have learned how to install and secure phpMyAdmin on a Debian 9 server. You can now use phpMyAdmin to manage your databases.

Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Jassweb.com/

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

Contact
San Vito Al Tagliamento 33078
Pordenone Italy
Item added to cart.
0 items - 0.00
Open chat
Scan the code
Hello 👋
Can we help you?