Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

Install and Secure phpMyAdmin on an Ubuntu Server

Set up the LAMP stack, install phpMyAdmin and protect it with a hidden URL, an IP allow list and HTTPS.

Databases3 min read4 steps

phpMyAdmin is a web tool to manage MySQL databases. Because it holds access to your data, security matters as much as the install.

Note: The source steps were written for Ubuntu 16.04, which is out of support. The same commands work on current Ubuntu LTS releases, and you should use a supported release for any real server.

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:

  1. Choose apache2 with the space bar and press Enter.
  2. Select Yes to configure the database with dbconfig-common.
  3. Enter the MySQL root password.
  4. 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
Note: Old Apache 2.2 syntax with 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.