Support Online
Skip to main content

phpMyAdmin Installation and Safe User Guide on Ubuntu

💡 What Will You Learn in This Guide?

In this guide, we will install phpMyAdmin step by step in Ubuntu 22.04 and above versions,
You will configure MySQL root access and add an extra layer of security with Apache .htaccess.
You'll also learn how to fix common installation problems like the $Validate Password$ error.

🧠 Stage 1 – Understanding the Content

Main Technical Topic

phpMyAdmin Installation and Secure Access Configuration on Ubuntu Server

What Problem Does It Solve?

It allows you to easily manage MySQL databases with the web-based phpMyAdmin interface instead of the command line.
It also blocks common vulnerabilities with HTTP authentication.

User Steps

  1. Installing phpMyAdmin and necessary PHP plugins
  2. Troubleshooting installation errors (especially Validate Password)
  3. Making MySQL root access password-based
  4. Enabling .htaccess support in Apache
  5. Add additional authentication with htpasswd

⚙️ 1. Installing phpMyAdmin and Required PHP Extensions

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

These commands install phpMyAdmin and the necessary PHP extensions.

Selections during installation:

Web sunucusu → apache2

dbconfig-common → Evet

phpMyAdmin MySQL şifresi → Güçlü bir parola oluşturun

Error Note:

Eğer Validate Password eklentisi aktifse hata alabilirsiniz. Bu durumda kurulumu durdurun ve eklentiyi devre dışı bırakın:
sudo mysql
UNINSTALL COMPONENT "file://component_validate_password";
exit
sudo apt install phpmyadmin

After installation, enable mbstring plugin:

sudo phpenmod mbstring
sudo systemctl restart apache2

🔐 2. Authorizing MySQL Root User with Password

In Ubuntu, the MySQL root account logs in with auth_socket by default. To use phpMyAdmin, switch to password-based method.

sudo mysql
ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'GucluSifre123!';
exit

This command puts the root account into password authentication mode.

Compatibility Note:

Eski PHP sürümleri için aşağıdaki yöntemi tercih edebilirsiniz:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'GucluSifre123!';

sudo mysql
CREATE USER 'webadmin'@'localhost' IDENTIFIED BY 'CokGucluSifre!';
GRANT ALL PRIVILEGES ON *.* TO 'webadmin'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
exit

This user can securely manage databases via phpMyAdmin.


🧱 4. Additional Layer of Security on Apache (.htaccess)

phpMyAdmin is a frequently hacked application. Therefore additional HTTP authentication must be added.

4.1. Enabling .htaccess Support

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

Add the following line to the <Directory /usr/share/phpmyadmin> block:

AllowOverride All

Save and restart Apache:

sudo systemctl restart apache2

4.2. Creating .htaccess File

sudo nano /usr/share/phpmyadmin/.htaccess

Make the content as follows:

AuthType Basic
AuthName "Giris Kisitlandi"
AuthUserFile /etc/phpmyadmin/.htpasswd
Require valid-user

4.3. Creating a Password User with htpasswd

sudo htpasswd -c /etc/phpmyadmin/.htpasswd genixnode_admin

Set a strong password for genixnode_admin. To add additional users, repeat the same command without using the -c parameter.

Test from browser: 🔗 https://tr1-node01.ornek.com/phpmyadmin

Now Apache authentication will be done first, then phpMyAdmin login will be done.


❓ Frequently Asked Questions (FAQ)

  1. Is remote access to phpMyAdmin secure?

No. Allow only trusted IP addresses or connect via VPN.

  1. Why doesn't .htaccess work?

The AllowOverride All directive may not have been added. Add it and restart Apache.

  1. I get an error when logging in to phpMyAdmin.

Your root account may still be using auth_socket. Execute the ALTER USER command again.

  1. Why is php-mbstring needed?

Required for correct display of UTF-8 and Turkish characters.

  1. How do I reset the htpasswd user?

Delete the old file or add a new user with the command sudo htpasswd /etc/phpmyadmin/.htpasswd new_user.


⚙️ Useful Commands

TransactionCommand
Start Apachesudo systemctl start apache2
Stop Apachesudo systemctl stop apache2
Restart Apachesudo systemctl restart apache2
Check MySQL statussudo systemctl status mysql
phpMyAdmin addresshttps://sunucu-adresiniz/phpmyadmin

🚀 Result

Congratulations! phpMyAdmin now runs securely on Ubuntu. You have added protection when managing your MySQL data with both encrypted access and HTTP authentication. ☁️ You can try this configuration immediately on secure, optimized Ubuntu servers on the GenixNode platform.