How to install MySQL Server and phpMyAdmin on a VPS (Apache)
This tutorial covers installing MySQL Server, PHP and phpMyAdmin on a Linux VPS using Apache.
Compatible with: Ubuntu 20.04 / 22.04 / 24.04
Requirements
- VPS with root access
- Updated Ubuntu system
- Apache installed
If you don't already have Apache:
apt update && apt upgrade -y
apt install apache2 -y
systemctl enable apache2
systemctl start apache2
1. Install MySQL Server
Install MySQL:
apt install mysql-server -y
Check if it is running:
systemctl status mysql
If not active:
systemctl start mysql
systemctl enable mysql
2. Configure MySQL Security
Run the security script:
mysql_secure_installation
Recommendations:
- VALIDATE PASSWORD: optional (you can enter N)
- Remove anonymous users: Y
- Disable remote root login: Y
- Remove test bench: Y
- Reload privileges: Y
3. Create user and database
Access MySQL:
mysql -u root -p
Create bank and user:
CREATE DATABASE meubanco;
CREATE USER 'usuario'@'%' IDENTIFIED BY 'SenhaForte123!';
GRANT ALL PRIVILEGES ON meubanco.* TO 'usuario'@'%';
FLUSH PRIVILEGES;
EXIT;
Note:
'%' allows remote access. For greater security, use a specific IP.
4. Install PHP and necessary extensions
apt install php libapache2-mod-php php-mysql php-cli php-curl php-mbstring php-xml php-zip -y
Restart Apache:
systemctl restart apache2
5. Install phpMyAdmin
apt install phpmyadmin -y
During installation:
- Choose: apache2
- Configure bank automatically: Yes
6. Enable phpMyAdmin on Apache
If it doesn't work automatically:
ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin
Restart:
systemctl restart apache2
7. Access phpMyAdmin
In the browser:
http://IP-DA-VPS/phpmyadmin
Login:
- User: root or the created user
- Password: the one previously defined
FAQ (Frequently Asked Questions)
I can't access phpMyAdmin
Check:
systemctl status apache2
Also confirm that port 80 is allowed on the firewall:
ufw allow 80
Error "Access denied for user 'root'"
In Ubuntu, root uses socket authentication.
Solution: use created user or change method:
mysql
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'SuaSenha';
FLUSH PRIVILEGES;
phpMyAdmin asks for missing extension
Install:
apt install php-mbstring php-zip php-gd php-json php-curl -y
Restart:
systemctl restart apache2
How to allow remote access to MySQL
Edit:
nano /etc/mysql/mysql.conf.d/mysqld.cnf
Change:
bind-address = 0.0.0.0
Restart:
systemctl restart mysql
And release it on the firewall:
ufw allow 3306
Is phpMyAdmin safe?
By default, it is not recommended to leave it public.
Recommendations:
- Protect with additional password (Apache/Nginx)
- Restrict by IP
- Change default URL (/phpmyadmin)
How to change phpMyAdmin URL
Example:
mv /var/www/html/phpmyadmin /var/www/html/painel-db
Access:
http://IP-DA-VPS/painel-db
How to remove phpMyAdmin
apt remove phpmyadmin -y
apt purge phpmyadmin -y
Good practices
- Do not use root in applications
- Create specific users per system
- Make frequent backups
- Restrict access to the bank
- Monitor connections
If you still need help, open a ticket with our support.