phpMyAdmin Installation and Security Configuration on Ubuntu Server
Keyword: phpMyAdmin installation
Meta Description: Install phpMyAdmin on Ubuntu, securely manage MySQL databases and add an extra layer of security. Step by step guide.
Database administration plays a critical role in large projects, and tools like phpMyAdmin make it easy to manage databases from the web interface. In this guide, you will learn how to install phpMyAdmin and security configurations on the Ubuntu server. While phpMyAdmin simplifies database management, we will also tell you how to take security measures.
What Will You Learn in This Guide?
- Installing phpMyAdmin and installing the necessary PHP modules.
- Configuring the encrypted login settings of the MySQL root user.
- Adding password authentication with Apache to improve phpMyAdmin security.
1. Step: phpMyAdmin Installation
First, update your server's package list to install phpMyAdmin and the necessary PHP modules:
sudo apt update
sudo apt install phpmyadmin php-mbstring php-zip php-gd php-json php-curl
- During installation, you must select the following options:
Web Server: select apache2.
Database Configuration: Check the dbconfig-common option as Yes.
phpMyAdmin Password: Set a password.
Note: When you encounter this step, press SPACE to select Apache.
- After the installation is complete, enable the mbstring module and restart Apache:
sudo phpenmod mbstring
sudo systemctl restart apache2
2. Step: Editing MySQL User Privileges
- In MySQL 5.7 and later, the root user uses auth_socket authentication by default. To log in with phpMyAdmin, you must configure password login.
Enable root user password login by logging into MySQL:
sudo mysql
- Enable root user's password login with the following command:
ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'guclu_sifreniz';
FLUSH PRIVILEGES;
EXIT;
Note: If you are using an older PHP version, you may prefer mysql_native_password:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'guclu_sifreniz';
3. Step: Improving phpMyAdmin Security
- phpMyAdmin is an application that is widely targeted by attacks. So we'll add an additional layer of security using .htaccess.
1. Enabling the Use of .htaccess
- Edit phpMyAdmin's Apache configuration file:
sudo nano /etc/apache2/conf-available/phpmyadmin.conf
- Add the following line to the Directory /usr/share/phpmyadmin block:
AllowOverride All
1. Creating the .htaccess File
- Now create the .htaccess file in the phpMyAdmin directory:
sudo nano /usr/share/phpmyadmin/.htaccess
- Add the following code inside:
AuthType Basic
AuthName "Restricted Files"
AuthUserFile /etc/phpmyadmin/.htpasswd
Require valid-user
2. Password File Definition
- Use htpasswd command to generate the password:
sudo htpasswd -c /etc/phpmyadmin/.htpasswd kullanici_adiniz
Note: You can update the password file without using the -c option to add additional users.
- Apply the changes by restarting Apache:
sudo systemctl restart apache2
Frequently Asked Questions (FAQ)
1. I'm getting "500 Internal Server Error" when logging in, why? This is usually caused by a typo in the .htaccess file or AllowOverride All permission not granted in the Apache configuration.
2. I'm getting the mbstring module error, what should I do? Make sure you enable the mbstring module and restart Apache:
sudo phpenmod mbstring
sudo systemctl restart apache2
3. I cannot log in with the root user, why? In MySQL 8+, the root user's encryption method must be updated to mysql_native_password or caching_sha2_password.
Result
Install phpMyAdmin on Ubuntu, secure it and manage MySQL databases over the web. Step by step installation guide.
Get started now on the GenixNode platform to experience database management on a professional infrastructure!

