phpMyAdmin is a web tool to manage MySQL databases. Because it holds access to your data, security matters as much as the install.
Step 1: Prepare the server
Install Ubuntu Server. Download the ISO from the Ubuntu website, create a bootable USB drive or DVD, boot from it and follow the installer. On a VPS the system is already installed for you.
Log in and update the packages:
sudo apt update
sudo apt upgrade
Step 2: Install the LAMP stack
sudo apt install apache2
sudo systemctl start apache2
Open the server IP in a browser to check Apache.
sudo apt install mysql-server
Set a strong root password for MySQL (run sudo mysql_secure_installation if asked).
sudo apt install php libapache2-mod-php php-mysql
sudo systemctl restart apache2
Step 3: Install phpMyAdmin
sudo apt install phpmyadmin
During the install:
- Choose apache2 with the space bar and press Enter.
- Select Yes to configure the database with dbconfig-common.
- Enter the MySQL root password.
- Set a password for the phpMyAdmin application and confirm it.
Step 4: Open phpMyAdmin
Go to http://your_server_ip/phpmyadmin. Log in with a MySQL user that has a password. On newer MySQL versions the root user uses socket login, so create a separate admin user:
sudo mysql
CREATE USER 'pmaadmin'@'localhost' IDENTIFIED BY 'StrongPassword';
GRANT ALL PRIVILEGES ON *.* TO 'pmaadmin'@'localhost' WITH GRANT OPTION;
EXIT;
Secure phpMyAdmin
Method 1: Change the URL
Bots look for /phpmyadmin. Edit the Apache file:
sudo nano /etc/phpmyadmin/apache.conf
Change the line Alias /phpmyadmin /usr/share/phpmyadmin to a different path, for example Alias /dbtools-8f3k /usr/share/phpmyadmin. Save and restart:
sudo systemctl restart apache2
Method 2: Allow only your IP
Create a config file:
sudo nano /etc/apache2/conf-available/phpmyadmin-restrict.conf
<Directory /usr/share/phpmyadmin>
Require ip your_ip_address
</Directory>
Enable and restart:
sudo a2enconf phpmyadmin-restrict
sudo systemctl restart apache2
Order Deny,Allow does not work on Apache 2.4. Use Require ip.Method 3: Use HTTPS
Without HTTPS, your database password travels in clear text.
sudo a2enmod ssl
sudo systemctl restart apache2
Install a certificate (for example with Certbot) and use https:// to open phpMyAdmin. Redirect HTTP to HTTPS in your virtual host.
Quick recap
- Install LAMP, then
sudo apt install phpmyadmin. - Change the URL, limit access by IP and use HTTPS.