How To Install phpMyAdmin on Ubuntu 22.04|20.04|18.04

Posted on 336 views

In our today’s guide, we will discuss how you can Install phpMyAdmin with Apache on Ubuntu 22.04|20.04|18.04. The phpMyAdmin package available on Ubuntu 22.04|20.04|18.04 repository is a bit old. If you need to install the latest phpMyAdmin on Ubuntu 22.04|20.04|18.04, you’ll have to download the package from the official phpMyAdmin releases page.

For Fedora guys, use our previous guide: How to Install and Configure phpMyAdmin on Fedora

What is phpMyAdmin?

phpMyAdmin is a free and Open source tool written in PHP used to administer MySQL and MariaDB database server from a Web interface. Most Developers prefer to use phpMyAdmin to interact with a database server because of its ease of using, plus advanced SQL editor which makes it easy to build and test complex SQL queries.

Step 1: Install PHP on Ubuntu on 22.04|20.04|18.04

The first software requirement for running phpMyAdmin is PHP. Since phpMyAdmin is written in PHP, you need to install it on the host system. The version of PHP can be the one available on the repository or a more recent version.

If you choose to go with the version of PHP available in your OS repositories, install it by running commands below in your terminal.

sudo apt update
sudo apt  install -y php php-tcpdf php-cgi php-pear php-mbstring libapache2-mod-php php-common php-phpseclib php-mysql

Step 2: Install MariaDB Database Server (Optional)

The next step is to install MariaDB database server if you don’t have one already.

sudo apt install mariadb-server

Secure your database server:

sudo mysql_secure_installation

You’ll need a non root user to access phpMyAdmin dashboard. If you don’t have one, you can create a test one.

Login to mysql shell:

sudo mysql -u root

Create test database and user.

GRANT ALL ON mydemo.* TO mydemo@localhost IDENTIFIED BY 'MyStrongDBPassw0rd';

Test login with created user.

$ mysql -u mydemo -pMyStrongDBPassw0rd
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 59
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)]> 

Step 3: Install Apache Web Server

For this installation setup, we chose Apache as a web server to use with phpMyAdmin. You are free to choose whichever web server you prefer though.

Install Apache on Ubuntu / Debian by running the following commands:

sudo apt-get -y install apache2

Step 4: Download phpMyAdmin on Ubuntu 22.04|20.04|18.04

You can check the released of phpMyAdmin from the downloads page. Thanks William Desportes for the hint on how to pull the latest release of phpMyAdmin.

Download latest version of phpMyAdmin with wget command.


Extract downloaded Archive:

tar xvf phpMyAdmin-latest-all-languages.tar.gz

Move the resulting folder to /usr/share/phpmyadmin folder.

sudo mv phpMyAdmin-*/ /usr/share/phpmyadmin

Create directory for phpMyAdmin temp files.

sudo mkdir -p /var/lib/phpmyadmin/tmp
sudo chown -R www-data:www-data /var/lib/phpmyadmin

Create directory for phpMyAdmin configuration files such as htpass file.

sudo mkdir /etc/phpmyadmin/

Create phpMyAdmin configuration file.

sudo cp /usr/share/phpmyadmin/  /usr/share/phpmyadmin/

Edit the file /usr/share/phpmyadmin/ and set secret passphrase:

$ sudo vim /usr/share/phpmyadmin/
$cfg['blowfish_secret'] = 'H2OxcGXxflSd8JwrwVlh6KW6s2rER63i'; 

Configure Temp directory:

$cfg['TempDir'] = '/var/lib/phpmyadmin/tmp';

Step 5: Configure Apache web Server

Create phpMyAdmin Apache configuration file:

sudo vim /etc/apache2/conf-enabled/phpmyadmin.conf

And paste below contents to the file:

Alias /phpmyadmin /usr/share/phpmyadmin

    Options SymLinksIfOwnerMatch
    DirectoryIndex index.php

            AddType application/x-httpd-php .php
            SetHandler application/x-httpd-php

        php_value include_path .
        php_admin_value upload_tmp_dir /var/lib/phpmyadmin/tmp
        php_admin_value open_basedir /usr/share/phpmyadmin/:/etc/phpmyadmin/:/var/lib/phpmyadmin/:/usr/share/php/php-gettext/:/usr/share/php/php-php-gettext/:/usr/share/javascript/:/usr/share/php/tcpdf/:/usr/share/doc/phpmyadmin/:/usr/share/php/phpseclib/
        php_admin_value mbstring.func_overload 0
            AddType application/x-httpd-php .php
            SetHandler application/x-httpd-php

        php_value include_path .
        php_admin_value upload_tmp_dir /var/lib/phpmyadmin/tmp
        php_admin_value open_basedir /usr/share/phpmyadmin/:/etc/phpmyadmin/:/var/lib/phpmyadmin/:/usr/share/php/php-gettext/:/usr/share/php/php-php-gettext/:/usr/share/javascript/:/usr/share/php/tcpdf/:/usr/share/doc/phpmyadmin/:/usr/share/php/phpseclib/
        php_admin_value mbstring.func_overload 0

# Authorize for setup

            AuthType Basic
            AuthName "phpMyAdmin Setup"
            AuthUserFile /etc/phpmyadmin/htpasswd.setup
        Require valid-user

# Disallow web access to directories that don't need it

    Require all denied

    Require all denied

    Require all denied

You can restrict access from specific IP by adding line like below:

Require ip
  • Where is your trusted subnet.

Restart apache web server.

sudo systemctl restart apache2

Step 6: Visit phpMyAdmin Web interface

Open the URL http://[ServerIP|Hostname]/phpmyadmin to login to phpMyAdmin dashboard with your Database credentials – username & password.


phpMyAdmin dashboard is displayed upon a successful login. It looks something like this:


Enjoy Administering MySQL / MariaDB database server using phpMyAdmin.


Gravatar Image
A systems engineer with excellent skills in systems administration, cloud computing, systems deployment, virtualization, containers, and a certified ethical hacker.