How to Install and Configure phpMyAdmin on Debian 12 Bookworm

Learn how to install and configure phpMyAdmin on Debian 12 Bookworm with this step-by-step guide.

Managing MySQL or MariaDB databases through the command line can sometimes be tedious and unintuitive, especially for new users. That’s where phpMyAdmin comes in — a free and open-source web-based interface that simplifies database management tasks. With a few clicks, users can create databases, run SQL queries, manage users and permissions, and more.

In this comprehensive guide, we will walk through the steps to install and configure phpMyAdmin on a system running Debian 12 (Bookworm). This tutorial is designed to be beginner-friendly but also detailed enough for more experienced users looking to fine-tune their phpMyAdmin setup.


Prerequisites

Before we begin, make sure your Debian 12 system meets the following requirements:

  • A running Debian 12 (Bookworm) server.
  • A non-root user with sudo privileges.
  • A LAMP stack (Linux, Apache, MySQL/MariaDB, PHP) already installed.
  • Internet connection and terminal access (SSH or direct login).

If your system doesn’t have the LAMP stack yet, we recommend setting it up first. You can follow this high-level command list:

sudo apt update
sudo apt install apache2
sudo apt install mariadb-server
sudo apt install php php-mysql libapache2-mod-php php-cli php-mbstring php-zip php-gd php-json php-curl

Once the LAMP stack is ready, proceed with the steps below.


Step 1: Update System Packages

Always start by updating your package list to ensure you are installing the latest versions of software packages.

sudo apt update && sudo apt upgrade -y

Step 2: Install phpMyAdmin

Debian 12 includes phpMyAdmin in its default package repositories, which makes installation straightforward.

sudo apt install phpmyadmin -y

During installation, you’ll be prompted with some configuration screens:

1. Web Server Selection

You’ll be asked to choose the web server that should be automatically configured. Use the spacebar to select Apache2 and then press Enter.

If you miss this step or accidentally skip it, you can manually configure Apache later.

2. Configure Database for phpMyAdmin

You’ll be asked whether to configure the database using dbconfig-common. Select Yes.

Then you’ll be prompted to provide a MySQL application password for phpMyAdmin. This password will be used internally by phpMyAdmin to communicate with the MySQL/MariaDB server. You can set a secure password or leave it blank to auto-generate one.


Step 3: Enable Required PHP Modules

phpMyAdmin requires certain PHP modules to function correctly. If they aren’t already installed, add them now:

sudo apt install php-mbstring php-zip php-gd php-json php-curl

After installation, restart Apache:

sudo systemctl restart apache2

Step 4: Enable phpMyAdmin in Apache

Sometimes, especially if you skipped the server configuration prompt during installation, the phpMyAdmin alias isn’t automatically enabled.

To ensure it’s active, check if the phpMyAdmin configuration file is linked in Apache’s config:

ls /etc/apache2/conf-enabled | grep phpmyadmin

If you don’t see a result, create a symlink:

sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf-enabled/phpmyadmin.conf
sudo systemctl reload apache2

Step 5: Access phpMyAdmin Web Interface

Once everything is configured, you can access phpMyAdmin in your browser:

http://your_server_ip/phpmyadmin

If you’re working on localhost:

http://localhost/phpmyadmin

You should see the phpMyAdmin login screen. Enter your MySQL or MariaDB credentials (typically the root or a privileged database user).

Note: On modern MariaDB installations, the root user is often set to use unix_socket authentication, meaning you can’t log in as root through phpMyAdmin by default. It’s recommended to create a dedicated user for phpMyAdmin access.


Step 6: Create a Dedicated MySQL User for phpMyAdmin

To securely access MySQL through phpMyAdmin, it’s better to avoid using the root account. Instead, create a new user:

sudo mariadb

Inside the MariaDB prompt:

CREATE USER 'pmauser'@'localhost' IDENTIFIED BY 'StrongPassword123!';
GRANT ALL PRIVILEGES ON *.* TO 'pmauser'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EXIT;

Now you can log into phpMyAdmin using pmauser and the password you set.


1. Change URL Alias

Changing the default /phpmyadmin URL can help avoid automated brute-force attempts.

Open Apache config for phpMyAdmin:

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

Find this line:

Alias /phpmyadmin /usr/share/phpmyadmin

Change it to something obscure, like:

Alias /mydbpanel /usr/share/phpmyadmin

Save and exit (Ctrl + X, then Y, then Enter), then reload Apache:

sudo systemctl reload apache2

Now access phpMyAdmin at:

http://your_server_ip/mydbpanel

2. Set Up Apache Basic Authentication

You can add an extra layer of authentication using .htaccess.

First, enable .htaccess support:

sudo nano /etc/phpmyadmin/apache.conf

Inside the <Directory /usr/share/phpmyadmin> block, add or modify:

AllowOverride All

Then create the password file:

sudo apt install apache2-utils
sudo htpasswd -c /etc/phpmyadmin/.htpasswd adminuser

You’ll be prompted to set a password for the adminuser.

Now create the .htaccess file:

sudo nano /usr/share/phpmyadmin/.htaccess

Add the following content:

AuthType Basic
AuthName "Restricted Access"
AuthUserFile /etc/phpmyadmin/.htpasswd
Require valid-user

Save and exit, then reload Apache:

sudo systemctl reload apache2

Now, when accessing phpMyAdmin, you’ll be prompted for the Apache-level username and password before reaching the phpMyAdmin login screen.


Step 8: Adjust PHP Settings for Better Performance (Optional)

Edit your php.ini file to adjust limits for large imports or long sessions:

sudo nano /etc/php/8.2/apache2/php.ini

Look for and modify the following values (adjust as needed):

upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 300

Save and restart Apache:

sudo systemctl restart apache2

Step 9: Test and Maintain

After installation and configuration, test common functions in phpMyAdmin:

  • Create a new database.
  • Run a test SQL query.
  • Import and export a small table.
  • Check the “Status” and “Variables” tabs for useful server information.

Periodically check for updates to phpMyAdmin and apply patches to keep your system secure:

sudo apt update && sudo apt upgrade

Conclusion

phpMyAdmin remains one of the most accessible tools for managing MySQL and MariaDB databases on Debian systems. With just a few installation and configuration steps, it provides a feature-rich web interface that simplifies database operations for administrators and developers alike.

By following the steps in this guide, you should now have a working and secure phpMyAdmin installation on Debian 12 Bookworm. You’ve also learned how to apply essential hardening techniques like changing the URL alias and enabling basic authentication.

Whether you’re managing small projects or handling enterprise applications, phpMyAdmin can be a valuable addition to your toolkit.