phpMyAdmin is a web-based tool for managing MySQL databases. It's useful for developers and site owners who prefer a GUI over the command line.
This guide shows you how to install and secure phpMyAdmin on Ubuntu 24.04.
Prerequisites
A VPS running Ubuntu 24.04 with LAMP stack installed (Apache, MySQL, PHP). Check our tutorial if you haven't set up LAMP yet.
Step 1: Install phpMyAdmin
sudo apt update
sudo apt install phpmyadmin -y
During installation, you'll be prompted to select a web server. Press Space to select Apache2, then Tab and Enter.
You'll also be asked to configure a database for phpMyAdmin. Select "Yes" and enter a password for phpMyAdmin's database user.
Step 2: Enable phpMyAdmin in Apache
The installer should automatically enable phpMyAdmin. If not, enable it manually:
sudo ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin
Reload Apache:
sudo systemctl reload apache2
Step 3: Access phpMyAdmin
Open your browser and visit:
http://your_server_ip/phpmyadmin
Login with your MySQL root username and password.
Step 4: Secure phpMyAdmin (Critical)
phpMyAdmin is a common target for attackers. You must secure it.
Method A: Set up a separate login password (basic auth)
Create a .htpasswd file:
sudo htpasswd -c /etc/phpmyadmin/.htpasswd admin
Create a .htaccess file in /usr/share/phpmyadmin/:
sudo nano /usr/share/phpmyadmin/.htaccess
Add this content:
AuthType Basic
AuthName "Restricted Access"
AuthUserFile /etc/phpmyadmin/.htpasswd
Require valid-user
Reload Apache.
Method B: Restrict by IP
Edit the Apache config file:
sudo nano /etc/apache2/conf-available/phpmyadmin.conf
Add your IP to the "Require" line:
<Directory /usr/share/phpmyadmin>
Options FollowSymLinks
DirectoryIndex index.php
Require ip 192.168.1.100
Require all denied
</Directory>
Replace 192.168.1.100 with your IP. Reload Apache.
Step 5: Change phpMyAdmin URL (Optional)
Moving phpMyAdmin to a non-standard URL reduces bot scanning.
sudo mv /usr/share/phpmyadmin /usr/share/phpmyadmin_secretname
Update the symlink:
sudo rm /var/www/html/phpmyadmin
sudo ln -s /usr/share/phpmyadmin_secretname /var/www/html/mysecret
Access phpMyAdmin at http://your_server_ip/mysecret.
Troubleshooting
404 Not Found – Ensure the symlink is correct. Check if phpMyAdmin is installed in /usr/share/.
Login error – Verify your MySQL username and password. If you forgot the root password, reset it via command line.
Blank page – PHP error. Check Apache error logs: sudo tail -f /var/log/apache2/error.log.
Next Steps
phpMyAdmin is now ready. Use it to manage databases, run queries, and backup tables. Remember to keep it secure and update regularly.