
A Step-by-Step Guide to Installing and Securing phpMyAdmin on Debian 10
Managing MySQL or MariaDB databases from the command line is powerful, but it can be cumbersome for daily tasks. phpMyAdmin provides a robust, web-based graphical interface that simplifies database administration, allowing you to manage users, tables, permissions, and execute SQL queries directly from your browser.
This comprehensive guide will walk you through the process of installing and, more importantly, securing phpMyAdmin on your Debian 10 server. Following these steps will give you a powerful tool while minimizing common security risks.
Prerequisites: What You Need Before You Start
Before we begin, ensure your system is ready. You will need:
- A server running Debian 10 (Buster).
- A non-root user with sudo privileges.
- A fully configured LAMP (Linux, Apache, MySQL/MariaDB, PHP) stack. If you haven’t set this up, you must have Apache2, a database server, and PHP installed and running.
Step 1: Installing phpMyAdmin
Debian’s official repositories contain the phpMyAdmin package, making the initial installation straightforward.
First, update your server’s package index to ensure you are getting the latest available versions.
sudo apt update
Next, install the main phpmyadmin package along with the necessary PHP extensions it relies on.
sudo apt install phpmyadmin php-mbstring php-zip php-gd php-json php-curl
The installation process will automatically begin and present you with a few configuration prompts.
Step 2: Configuring the Installation
During the installation, you’ll see a series of full-screen prompts. Pay close attention to these steps to ensure phpMyAdmin is configured correctly.
Web Server Selection: You will be asked to choose the web server that should be automatically configured. Use the arrow keys to navigate, and press
SPACEto select apache2. An asterisk[*]will appear next to your selection. Once selected, pressTABto highlight<Ok>and then hitENTER.Database Configuration: The next screen will ask if you want to use
dbconfig-commonto configure a database for phpMyAdmin’s internal use. This is the recommended approach. Select Yes and pressENTER.Create a Password: You will now be prompted to create a password for the
phpmyadminuser to connect to the database. It is critical to choose a strong, unique password here and store it securely. This is not your MySQL root password; it is a new password created specifically for phpMyAdmin’s internal operations.
Once you confirm the password, the installation will complete. The installer automatically adds the phpMyAdmin Apache configuration file into the /etc/apache2/conf-enabled/ directory, making it live immediately.
To finalize the changes, restart the Apache web server.
sudo systemctl restart apache2
Step 3: Accessing the phpMyAdmin Web Interface
Your phpMyAdmin installation is now active. You can access it by navigating to your server’s public IP address or domain name, followed by /phpmyadmin.
http://your_server_ip/phpmyadmin
You will see a login page. You can log in using your MySQL root user credentials or any other database user you have configured. Upon successful login, you will see the main dashboard, where you can begin managing your databases.
Crucial Security Measures for phpMyAdmin
Installing phpMyAdmin is easy, but leaving it with the default settings makes it a prime target for automated attacks. Securing your installation is not optional—it is an essential step.
1. Secure Access with a .htaccess Gateway
One of the most effective ways to protect your login page is to place it behind an additional server-level password prompt. This forces attackers to bypass two separate authentication layers.
First, you need to enable .htaccess file overrides for the phpMyAdmin directory. Edit the phpMyAdmin Apache configuration file:
sudo nano /etc/apache2/conf-available/phpmyadmin.conf
Inside the <Directory /usr/share/phpmyadmin> block, add the line AllowOverride All.
<Directory /usr/share/phpmyadmin>
Options SymLinksIfOwnerMatch
DirectoryIndex index.php
AllowOverride All
. . .
</Directory>
Save and close the file. Now, create the .htaccess file itself:
sudo nano /usr/share/phpmyadmin/.htaccess
Add the following content to the file. This sets up basic authentication.
AuthType Basic
AuthName "Restricted Files"
AuthUserFile /etc/phpmyadmin/.htpasswd
Require valid-user
Save and close this file. Next, create the password file (.htpasswd) mentioned in the configuration. Use the htpasswd utility to create the file and add your first user. Use the -c flag for the first user only.
sudo htpasswd -c /etc/phpmyadmin/.htpasswd your_username
You will be prompted to create and confirm a password for your_username. To add more users later, run the same command without the -c flag.
Finally, restart Apache to apply all changes.
sudo systemctl restart apache2
Now, when you visit http://your_server_ip/phpmyadmin, you will be greeted by a pop-up authentication prompt before you can even see the phpMyAdmin login page.
2. Change the Default Access URL
Bots and attackers constantly scan for the default /phpmyadmin path. Changing this to a unique, obscure URL dramatically reduces your exposure.
Open the configuration file again:
sudo nano /etc/apache2/conf-available/phpmyadmin.conf
Find the line that reads Alias /phpmyadmin /usr/share/phpmyadmin. Change /phpmyadmin to something difficult to guess.
# Alias /phpmyadmin /usr/share/phpmyadmin
Alias /secret-db-manager /usr/share/phpmyadmin
Save the file and restart Apache once more.
sudo systemctl restart apache2
Your phpMyAdmin interface will now only be accessible at http://your_server_ip/secret-db-manager.
Conclusion
You have now successfully installed and secured phpMyAdmin on your Debian 10 server. By implementing an additional authentication layer and obscuring the access URL, you have significantly hardened your database management tool against common threats. With this powerful and secure interface at your disposal, you can efficiently manage your databases with confidence.
Source: https://kifarunix.com/install-phpmyadmin-on-debian-10-buster/


