Support Online
Skip to main content

phpMyAdmin Installation and Security Settings on Ubuntu 22.04

What will you learn in this guide?

In this guide, on a server running Ubuntu 22.04
phpMyAdmin installation, MySQL user settings
and you will learn how to take additional security measures with Apache.

🧠 Technical Summary

Subject: Installing and securing phpMyAdmin
Problem: Need for web interface instead of command line
Steps: Setup → Authentication → Authorization → Security


What is phpMyAdmin?

phpMyAdmin allows you to manage MySQL databases via web browser.
It offers a visual management interface that is an alternative to the command line.


Security Warning

phpMyAdmin accesses the database directly.
Therefore without HTTPS should never be used.

If you do not have a domain name and an SSL certificate, HTTPS must be configured first.


Prerequisites

  • Server with Ubuntu 22.04 installed
  • User with authority sudo
  • Apache, MySQL and PHP installed (LAMP)
  • UFW firewall active

1. phpMyAdmin Installation

Update package list

sudo apt update
  • This command updates system packages.

Install required packages


sudo apt install phpmyadmin php-mbstring php-zip php-gd php-json php-curl
  • This command installs phpMyAdmin and necessary PHP extensions.

Selections during installation

  1. Server: apache2

  2. dbconfig-common: Yes

  3. MySQL application password: A strong password


Validate Password Error Solution (If Necessary)
  1. Enter the MySQL console

sudo mysql

  1. Disable the password verification component

UNINSTALL COMPONENT "file://component_validate_password";

Sign out


exit

  • Start the installation again:

sudo apt install phpmyadmin

  • Reactivate the component after installation:

INSTALL COMPONENT "file://component_validate_password";

Apache and PHP Configuration

  1. Activate mbstring plugin

sudo phpenmod mbstring
  • This command turns on multibyte character support.

Restart Apache


sudo systemctl restart apache2

2. MySQL Authentication Settings

  1. In Ubuntu, MySQL root user uses auth_socket by default.
  • phpMyAdmin requires password authentication.

Connect to MySQL


sudo mysql

  1. Check available verification methods

SELECT user, plugin, host FROM mysql.user;

  1. Turn on password authentication for root

ALTER USER 'root'@'localhost'
IDENTIFIED WITH caching_sha2_password BY 'GucluBirParola';
  • Mysql_native_password can be used if necessary.

Alternative: Custom MySQL User

  • Create new user

CREATE USER 'dbadmin'@'localhost'
IDENTIFIED WITH mysql_native_password BY 'GucluBirParola';

Authorize


GRANT ALL PRIVILEGES ON *.* TO 'dbadmin'@'localhost' WITH GRANT OPTION;

  • Log out

exit
  • phpMyAdmin Access

Open the following address from the browser:


https://sunucu_adresi/phpmyadmin
  • After Apache authentication, MySQL user information is requested.

3. Improving phpMyAdmin Security

  1. Edit Apache configuration

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

  1. Add AllowOverride

<Directory /usr/share/phpmyadmin>
AllowOverride All
</Directory>

  1. Restart Apache

sudo systemctl restart apache2

Additional Security with .htaccess

  1. Create the file

sudo nano /usr/share/phpmyadmin/.htaccess

  1. Add content

AuthType Basic
AuthName "Restricted Access"
AuthUserFile /etc/phpmyadmin/.htpasswd
Require valid-user
  • Creating an Apache User
  • Create the password file


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

Restart Apache


sudo systemctl restart apache2
  • This action adds a second layer of security to phpMyAdmin.

Frequently Asked Questions (FAQ)

1. Is phpMyAdmin secure? Yes, it is secure if configured correctly.

2. Is HTTPS mandatory? Yes, highly recommended.

3. Should I log in with root? No, a special user should be preferred.

4. Is .htaccess really necessary? Yes, it significantly reduces the risk of attack.


Result

With this guide, you have got phpMyAdmin installed, authorized and secure on Ubuntu.

You can immediately configure your servers on the GenixNode infrastructure to perform database management safely.