How to Install phpMyAdmin on Ubuntu 24.04
If you manage databases in MySQL or MariaDB, phpMyAdmin is an excellent web-based interface to simplify database management. In this guide, I’ll walk you through the process of installing phpMyAdmin on Ubuntu 24.04.
Prerequisites
Before installing phpMyAdmin, ensure that you have:
- Ubuntu 24.04 up and running.
- LAMP Stack (Linux, Apache, MySQL/MariaDB, PHP) installed. If you don’t have it, run the following commands to set it up:
sudo apt update
sudo apt install apache2
sudo apt install mysql-server
sudo apt install php libapache2-mod-php php-mysql
Step 1: Install phpMyAdmin
Ubuntu’s official package repository includes phpMyAdmin, so you can install it using apt. Start by updating your package index:
sudo apt update
Then, install phpMyAdmin:
sudo apt install phpmyadmin
During installation, the system will prompt you with several configuration steps:
- Web server selection: Choose
apache2and press Enter. - Database configuration: Select “Yes” when prompted about configuring the database for phpMyAdmin.
- MySQL root password: You’ll need to set a password for phpMyAdmin to connect to your database.
If you’re not prompted for database configuration, you can manually set up phpMyAdmin using MySQL in the next step.
Step 2: Manually Create the MySQL User for phpMyAdmin (Optional)
If the setup didn’t ask for MySQL configuration, or if you wish to create a custom user, follow these steps:
- Log in to the MySQL shell:
sudo mysql
- Create a new MySQL user and grant it the necessary privileges:
CREATE USER 'phpmyadmin'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON *.* TO 'phpmyadmin'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EXIT;
Replace your_password with a strong password of your choice.
Step 3: Enable the phpMyAdmin Apache Configuration
If the installer didn’t automatically configure Apache, you’ll need to enable the phpMyAdmin configuration manually:
sudo ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin
After that, restart Apache to apply the changes:
sudo systemctl restart apache2
Step 4: Access phpMyAdmin
Once phpMyAdmin is installed and configured, you can access it by navigating to the following URL in your web browser:
http://your_server_ip/phpmyadmin
Log in using the MySQL root account or the phpMyAdmin user you created earlier.
Step 5: Secure Your phpMyAdmin Installation
To improve security, it’s recommended to set up additional layers of protection, such as Apache Basic Authentication.
- Create a
.htaccessfile for phpMyAdmin:
sudo nano /usr/share/phpmyadmin/.htaccess
- Add the following lines to enable password protection:
AuthType Basic
AuthName "Restricted Access"
AuthUserFile /etc/phpmyadmin/.htpasswd
Require valid-user
- Create a password file and assign a user:
sudo htpasswd -c /etc/phpmyadmin/.htpasswd your_user
- Restart Apache:
sudo systemctl restart apache2
Now, when accessing phpMyAdmin, you’ll first need to authenticate with your Apache user credentials before logging in to phpMyAdmin.
You’ve successfully installed and secured phpMyAdmin on your Ubuntu 24.04 system. From here, you can manage your databases, run queries, and perform various administrative tasks through the web interface.
