On Ubuntu 24.04, install MySQL and PHP, then run sudo apt install phpmyadmin and pick apache2. phpMyAdmin then opens at your-server-ip/phpmyadmin.
1. Install MySQL and PHP
phpMyAdmin needs a database server and PHP. This installs MySQL, PHP and the PHP module for Apache:
sudo apt update
sudo apt install mysql-server php libapache2-mod-php php-mysql
Prefer MariaDB? Install mariadb-server instead of mysql-server; the rest of this article works the same.
Run the security script. It removes the test database and anonymous users; answer y to its questions:
sudo mysql_secure_installation
It also asks whether to set up the VALIDATE PASSWORD component. If you say yes, read the first problem under Common problems below before you install phpMyAdmin.
Check both are working:
sudo systemctl status mysql --no-pager
php -v
MySQL should show active (running) (with MariaDB, use mariadb instead of mysql) and PHP should print its version.
This combination of Linux, Apache, MySQL and PHP (often called LAMP) is also what PHP applications such as WordPress or e107 need. Put each application in its own website folder, as shown in Host several websites on one server with Apache.
2. Install phpMyAdmin
sudo apt install phpmyadmin php-mbstring php-zip php-gd php-curl
The installer asks a few questions:
Web server to reconfigure automatically:
apache2is highlighted but not yet selected. Press the Space bar so a*appears next to it, then Tab to <Ok> and press Enter. If you skip the Space bar, phpMyAdmin won't be added to Apache.Configure database for phpmyadmin with dbconfig-common?: choose <Yes>.
MySQL application password for phpmyadmin: enter a strong password, or leave it empty to get a random one. phpMyAdmin uses this internally; you won't log in with it.
The installer adds phpMyAdmin to Apache and reloads it. Check that the Apache part is switched on:
ls -l /etc/apache2/conf-enabled/phpmyadmin.conf
The file should exist. If it doesn't, see "Not Found" at /phpmyadmin under Common problems below.
3. Create a MySQL user to log in with
On Ubuntu, the MySQL root user logs in through the system account, not with a password, so you can't use it in phpMyAdmin. Create your own admin user instead. Open MySQL:
sudo mysql
Run these lines, with your own user name and a strong password:
CREATE USER 'dbadmin'@'localhost' IDENTIFIED BY 'choose-a-strong-password';
GRANT ALL PRIVILEGES ON *.* TO 'dbadmin'@'localhost' WITH GRANT OPTION;
EXIT;
This user can manage every database on the server. For a single website, create a user with rights only on that site's database instead.
4. Log in
Open http://your-server-ip/phpmyadmin (or https://example.com/phpmyadmin if a domain with SSL points to the server). Log in with the user from step 3. You should see your databases in the list on the left.
5. Protect phpMyAdmin
Bots try /phpmyadmin on every server they find. Do at least one of these:
- Only log in over HTTPS, so your password isn't sent in plain text. Set up SSL for a domain on the server as shown in Host several websites on one server with Apache and use that domain to open phpMyAdmin.
- Allow only your own IP address. Open the phpMyAdmin Apache settings:
Inside thesudo nano /etc/phpmyadmin/apache.conf<Directory /usr/share/phpmyadmin>block, add a line with your IP address (find it by searching "what is my IP"):
Save, then check and reload Apache:Require ip 203.0.113.25
Other visitors now get 403 Forbidden. If your IP address changes, update the line. When a phpMyAdmin update later asks about this changed file, keep your version.sudo apache2ctl configtest && sudo systemctl reload apache2
Common problems
"ERROR 1819: Your password does not satisfy the current policy requirements"
This happens during the phpMyAdmin installation when the VALIDATE PASSWORD component is on. Choose abort, switch the component off, install phpMyAdmin, then switch it back on:
sudo mysql -e 'UNINSTALL COMPONENT "file://component_validate_password";'
sudo apt install phpmyadmin
sudo mysql -e 'INSTALL COMPONENT "file://component_validate_password";'
If apt says phpMyAdmin is already installed, run sudo dpkg-reconfigure phpmyadmin in the middle step instead.
These commands are for MySQL. MariaDB doesn't use this component.
"Not Found" at /phpmyadmin
apache2 wasn't selected during the installation. Run the setup again and select it with the Space bar:
sudo dpkg-reconfigure phpmyadmin
Or switch on the Apache settings yourself:
sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf-available/phpmyadmin.conf
sudo a2enconf phpmyadmin
sudo systemctl reload apache2
"Access denied for user 'root'@'localhost'"
The MySQL root user can't log in with a password on Ubuntu. Use the user you created in step 3.
The page shows PHP code or downloads a file
Apache isn't running PHP. Install the module and restart Apache: sudo apt install libapache2-mod-php, then sudo systemctl restart apache2.
"The mysqli extension is missing"
Install it with sudo apt install php-mysql, then restart Apache.
Related articles
- Install the Apache web server on Ubuntu
- Host several websites on one server with Apache
- Connect to your server with SSH
Still stuck? Open a support ticket and we'll help.