phpMyAdmin is a free, open-source tool that makes it easier to manage MySQL and MariaDB databases via a web interface. With features like user management, query execution, and export/import functionality, phpMyAdmin simplifies database tasks for both beginners and advanced users. You can easily configure phpMyAdmin to suit your server environment and streamline database operations efficiently.

This article will guide you through the steps to install, configure, secure, and maintain phpMyAdmin on a Linux server.
Prerequisites
Before you begin, ensure that you meet the following prerequisites:
- A Linux server running Ubuntu, Debian, or CentOS.
- A LAMP (Linux, Apache, MySQL/MariaDB, PHP) or LEMP (Linux, Nginx, MySQL/MariaDB, PHP) stack installed.
- Root or sudo privileges are required to install software and make configuration changes.
- Access to the terminal or SSH for remote configuration.
Installing phpMyAdmin
Before configuring, you need to install phpMyAdmin on your Linux machine.
Update System Packages
Before installing phpMyAdmin, it’s important to ensure that your system packages are up to date. This helps avoid any potential conflicts during the installation.
- For Ubuntu/Debian:
sudo apt update && sudo apt upgrade
- For CentOS/RHEL:
sudo yum update
Install phpMyAdmin
Once the system is updated, proceed with installing phpMyAdmin.
- For Ubuntu/Debian:
sudo apt install phpmyadmin
- For CentOS/RHEL:
phpMyAdmin can be installed from the EPEL (Extra Packages for Enterprise Linux) repository. First, install EPEL, then install phpMyAdmin:
sudo yum install epel-release
sudo yum install phpmyadmin
Verify phpMyAdmin Installation
After the installation is complete, verify that phpMyAdmin is installed and running. Open a web browser and navigate to the following URL:
- For Apache:
http://<server_ip>/phpmyadmin
- For Nginx: Ensure the server block is correctly configured to point to phpMyAdmin.
If phpMyAdmin loads successfully, your installation is complete.
Configure phpMyAdmin
To use phpMyAdmin effectively, you need to configure both your web server (Apache or Nginx) and PHP environment. This setup ensures proper connectivity, performance, and compatibility, allowing seamless management of MySQL or MariaDB databases through the web interface.
Configure Web Server (Apache/Nginx)
For Apache:
- Create a symbolic link to phpMyAdmin in the web root directory:
sudo ln -s /usr/share/phpmyadmin /var/www/html/
- Enable phpMyAdmin by including the configuration in Apache’s main configuration file:
sudo nano /etc/apache2/apache2.conf
- Add the following line at the end:
Include /etc/phpmyadmin/apache.conf
For Nginx:
- Open the server block configuration file for your site:
sudo nano /etc/nginx/sites-available/default
- Inside the
server
block, add a location block to serve phpMyAdmin:
location /phpmyadmin { root /usr/share; index index.php; try_files $uri $uri/ =404; }
- Save the file and restart Nginx:
sudo systemctl restart nginx
PHP Configuration for phpMyAdmin
phpMyAdmin requires several PHP extensions to function correctly. Ensure these extensions are installed:
- For Ubuntu/Debian:
sudo apt install php-mbstring php-zip php-gettext
- After installing the required PHP extensions, restart your web server to apply changes:
For Apache:
sudo systemctl restart apache2
For Nginx:
sudo systemctl restart nginx
Securing phpMyAdmin in Linux
Protecting phpMyAdmin with Authentication (Apache)
By default, phpMyAdmin is open to anyone with access to the server. To improve security, use .htaccess
and .htpasswd
for basic authentication.
- Create a
.htpasswd
file to store user credentials:
sudo htpasswd -c /etc/phpmyadmin/.htpasswd <username>
- Enable
.htaccess
in Apache’s configuration file:
sudo nano /etc/apache2/apache2.conf
- Inside the
<Directory /usr/share/phpmyadmin>
directive, add:
AllowOverride All
- Create a
.htaccess
file in/usr/share/phpmyadmin
with the following content:
AuthType Basic AuthName "Restricted Access" AuthUserFile /etc/phpmyadmin/.htpasswd Require valid-user
Configuring SSL for Secure Connections
It is highly recommended to configure SSL to encrypt the connection to phpMyAdmin.
- For Apache, enable SSL:
sudo a2enmod ssl sudo systemctl restart apache2
- Then configure an SSL certificate for your domain. Use Let’s Encrypt or a self-signed certificate.
- For Nginx, ensure SSL is enabled in your server block configuration.
Restricting phpMyAdmin Access by IP
To further secure phpMyAdmin, restrict access to specific IP addresses.
For Apache:
Edit the /etc/apache2/apache2.conf
file and modify the <Directory /usr/share/phpmyadmin>
block:
<Directory /usr/share/phpmyadmin>
Order Deny,Allow
Deny from all
Allow from <your_ip>
</Directory>
For Nginx:
In the server block for phpMyAdmin, use the allow
and deny
directives:
location /phpmyadmin {
allow <your_ip>;
deny all;
}
Configuring phpMyAdmin with MySQL/MariaDB
Database Configuration
phpMyAdmin automatically detects MySQL/MariaDB configurations. To confirm or modify, you can edit the config-db.php
file located in /etc/phpmyadmin/
.
User Authentication Methods
In the config.inc.php
file, set the authentication method. The default method is cookie
, but you can configure other methods like config
or http
.
$cfg['Servers'][$i]['auth_type'] = 'cookie';
Multi-Server Configuration
If you want to manage multiple MySQL/MariaDB servers, phpMyAdmin allows adding configurations for each server in the config.inc.php
file.
Testing phpMyAdmin
Accessing phpMyAdmin via Web Browser
To test phpMyAdmin, open your web browser and visit http://<server_ip>/phpmyadmin
or https://<server_ip>/phpmyadmin
for secure access.
Log in with your MySQL/MariaDB credentials, and you should be able to manage your databases.
Troubleshooting Common Issues
- Login Issues: Verify the correct username and password. Make sure the MySQL/MariaDB user has the necessary privileges.
- Access Denied: Ensure that your Apache or Nginx configuration allows traffic from your IP.
- Missing Dependencies: Check if the required PHP extensions (like
php-mbstring
,php-zip
) are installed.
Advanced phpMyAdmin Configurations
Enabling Two-Factor Authentication: To add an extra layer of security, you can enable two-factor authentication (2FA) in phpMyAdmin using plugins or custom configurations. This step will require you to install additional libraries or set up 2FA mechanisms.
Customizing the phpMyAdmin Interface: You can personalize the phpMyAdmin interface by modifying settings in the config.inc.php
file, such as changing the theme or default language.
Performance Tuning phpMyAdmin: For servers with heavy database traffic, it is essential to optimize phpMyAdmin performance. You can adjust PHP settings like memory limits and execution time in php.ini
or optimize server-side MySQL/MariaDB performance.
Regular Maintenance of phpMyAdmin
Updating phpMyAdmin
phpMyAdmin should be regularly updated to ensure that you’re protected from known vulnerabilities. Update phpMyAdmin by running:
- For Ubuntu/Debian:
sudo apt update && sudo apt upgrade phpmyadmin
- For CentOS/RHEL:
sudo yum update phpmyadmin
Backup and Restore of phpMyAdmin Configuration
Regular backups of your phpMyAdmin configurations and MySQL/MariaDB databases are essential for disaster recovery. Use phpMyAdmin’s export feature to backup databases and configuration files.
Conclusion
By following the steps in this guide, you’ve successfully installed and configured phpMyAdmin on your Linux server. You’ve also implemented essential security measures to protect your phpMyAdmin installation. Regular updates and backups are crucial for maintaining the stability and security of your system. Consider further optimizations, such as enabling two-factor authentication and fine-tuning performance, as your server grows.