Install phpMyAdmin on Ubuntu 20.04 | 18.04 with Apache

This brief tutorial shows students and new users how to install phpMyAdmin on Ubuntu 20.04 | 18.04.

phpMyAdmin is an open source web-based tool that allows users to easily manage MySQL or MariaDB databases.

For those not comfortable using the comment line interface to manage databases, phpMyAdmin web interface is a great alternative.

With phpMyAdmin, you’ll be able to manage MySQL databases, user accounts and privileges, execute SQL-statements, import and export data in a variety of data formats and much more.

To get started, continue with the steps below:

Step 1: Install Apache

Apache2 HTTP Server is the most popular web server in use… so install it since you’ll needs it to run phpMyAdmin.

To install Apache2 HTTP on Ubuntu server, run the commands below…

sudo apt update
sudo apt install apache2

After installing Apache2, the commands below can be used to stop, start and enable Apache2 service to always start up with the server boots.

sudo systemctl stop apache2.service
sudo systemctl start apache2.service
sudo systemctl enable apache2.service

To find out if Apache2 HTTP server is installed, simply open your web browser and type in the server’s IP or hostname.

When you see the page similar to the one below, then Apache2 is installed and working.


Step 2: Install MariaDB

For this tutorial, we’re going to be installing MariaDB server to manage via phpMyAdmin.

To install MariaDB run the commands below.

sudo apt install mariadb-server mariadb-client

After installing MariaDB, the commands below can be used to stop, start and enable MariaDB service to always start up when the server boots..

Run these on Ubuntu

sudo systemctl stop mariadb.service
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service

After that, run the commands below to secure MariaDB server by creating a root password and disallowing remote root access.

sudo mysql_secure_installation

When prompted, answer the questions below by following the guide.

  • Enter current password for root (enter for none): Just press the Enter
  • Set root password? [Y/n]: Y
  • New password: Enter password
  • Re-enter new password: Repeat password
  • Remove anonymous users? [Y/n]: Y
  • Disallow root login remotely? [Y/n]: Y
  • Remove test database and access to it? [Y/n]:  Y
  • Reload privilege tables now? [Y/n]:  Y

Restart MariaDB server

Even though you configured a password above, when you run the commands below you will be granted access without requiring a password.

sudo mysql

You’ll automatically be granted access.

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 44
Server version: 10.3.22-MariaDB-1ubuntu1 Ubuntu 20.04

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 

This happens because the current version 8.0 comes with a feature that provides root authentication via a auth_socket plugin.

This plugin authenticates users who connect from the localhost via socket file without prompting or a password.

This can cause issues with some apps that need to connect to the database via root. To fix that, you’ll need to change the default authentication mechanism from auth_socket to mysql_native_password.

Login back into MariaDB console.

sudo mysql

Then run the commands below to change to disable mysql_native_password module..

USE mysql;
UPDATE user SET plugin='' WHERE user ='root';

The save your changes and exit:


That will do it.

Restart MariaDB for the changes above to take place.

You should be prompted for password when you want to access MariaDB console.

sudo mysql -u root -p

Since you don’t want to use MariaDB root user for external applications to connect, you should probably create an admin account separate from the root user.

GRANT ALL PRIVILEGES ON *.* TO 'superadmin'@'localhost' IDENTIFIED BY 'very_strong_password';

Continue below.

Step 3: Install PHP 7.4 and Related Modules

PHP 7.4 may not be available in Ubuntu default repositories… in order to install it, you will have to get it from third-party repositories.

Run the commands below to add the below third party repository to upgrade to PHP 7.4

sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php

Then update and upgrade to PHP 7.4

sudo apt update

Next, run the commands below to install PHP 7.4 and related modules.

sudo apt install php7.4 libapache2-mod-php7.4 php7.4-common php7.4-gmp php7.4-curl php7.4-intl php7.4-mbstring php7.4-xmlrpc php7.4-mysql php7.4-gd php7.4-bcmath php7.4-xml php7.4-cli php7.4-zip

After installing PHP 7.4, run the commands below to open PHP default config file for Apache2.

sudo nano /etc/php/7.4/apache2/php.ini

Then make the changes on the following lines below in the file and save. The value below are great settings to apply in your environments.

file_uploads = On
allow_url_fopen = On
short_open_tag = On
memory_limit = 256M
upload_max_filesize = 100M
max_execution_time = 360
max_input_vars = 1500
date.timezone = America/Chicago

After making the change above, save the file and close out.

Step 4: Install phpMyAdmin

Now that Apache and PHP are installed the final step is to install phpMyAdmin and configure. To do that, run the commands below

sudo apt install phpmyadmin

When prompted to choose the webserver, selecat apache2 and continue.

+------------------------+ Configuring phpmyadmin +-------------------------+
 | Please choose the web server that should be automatically configured to   |
 | run phpMyAdmin.                                                           |  
 | Web server to reconfigure automatically:                                  |
 |                                                                           |
 |    [*] apache2                                                            |
 |    [ ] lighttpd                                                           |                                                 | 
 |                                 <ok>                                                                            |

When prompted again to allow debconfig-common to install a database and configure select No.

 +------------------------+ Configuring phpmyadmin +-------------------------+
 |                                                                           |
 | The phpmyadmin package must have a database installed and configured      |
 | before it can be used.  This can be optionally handled with               |
 | dbconfig-common.                                                          |
 |                                                                           |
 | If you are an advanced database administrator and know that you want to   |
 | perform this configuration manually, or if your database has already      |
 | been installed and configured, you should refuse this option.  Details    |
 | on what needs to be done should most likely be provided in                |
 | /usr/share/doc/phpmyadmin.                                                |
 |                                                                           |
 | Otherwise, you should probably choose this option.                        |
 |                                                                           |
 | Configure database for phpmyadmin with dbconfig-common?                   |
 |                                                                           |
 |                  <Yes>                  <No>                              |
 |                                                                           |

After installing, run the commands below to logon to the database server to enable phpMyAdmin root logon.

Now, open your web browser and login to the server hostname or IP address followed by phpmyadmin

ex. http://localhost/phpmyadmin

phpMyAdmin with Apache on Ubuntu

Logon with MySQL root account you created earlier.

phpMyAdmin with Apache on Ubuntu

That’s it!


This post showed you how to install phpMyAdmin on Ubuntu 20.04 | 18.04. If you find any error above, please use the comment form below to report it.


You may also like the post below:


  1. phpMyAdmin root logon.

    No such command. Is there a typo to the command above ?


  2. sudo nano /etc/apache2/apache2.conf
    Then add the following line to the end of the file.

    Include /etc/phpmyadmin/apache.conf
    Then restart apache

    /etc/init.d/apache2 restart

    1. thanks for the include command.

  3. After complete installation of Phpmyadmin I hit the below link in browser but It give me site not reached error is some kind of vhost issue.Please guide

  4. Thank you so much for the tip on changing the connection type from socket for MariaDB. Much appreciated.

  5. Its showing php script while accessing local/phpmyadmin

  6. Please add the commands mentioned here in your tutorial. It’s missing and confuses the reader:

  7. it gives 404 error in my machine

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.