In our today’s guide, we will discuss how you can Install phpMyAdmin with Apache on Ubuntu 18.04 / Debian 9. The phpMyAdmin package available on Ubuntu 20.04/18.04 & Debian 9 repository is a bit old. If you need to install the latest phpMyAdmin on Ubuntu 20.04/18.04 / Debian 9, 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 / Debian

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-get 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

The next step is to install MariaDB database server.

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 [email protected] 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 20.04/18.04 / Debian 9

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.

DATA="$(wget -q -O-)"
URL="$(echo $DATA | cut -d ' ' -f 3)"
VERSION="$(echo $DATA | cut -d ' ' -f 1)"

For English language only package, use:


Extract downloaded Archive:

tar xvf phpMyAdmin-${VERSION}-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

<Directory /usr/share/phpmyadmin>
    Options SymLinksIfOwnerMatch
    DirectoryIndex index.php

    <IfModule mod_php5.c>
        <IfModule mod_mime.c>
            AddType application/x-httpd-php .php
        <FilesMatch ".+\.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
    <IfModule mod_php.c>
        <IfModule mod_mime.c>
            AddType application/x-httpd-php .php
        <FilesMatch ".+\.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
<Directory /usr/share/phpmyadmin/setup>
    <IfModule mod_authz_core.c>
        <IfModule mod_authn_file.c>
            AuthType Basic
            AuthName "phpMyAdmin Setup"
            AuthUserFile /etc/phpmyadmin/htpasswd.setup
        Require valid-user

# Disallow web access to directories that don't need it
<Directory /usr/share/phpmyadmin/templates>
    Require all denied
<Directory /usr/share/phpmyadmin/libraries>
    Require all denied
<Directory /usr/share/phpmyadmin/setup/lib>
    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.

install phpmyadmin debian ubuntu 01

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

install phpmyadmin debian ubuntu 02

Enjoy Administering MySQL / MariaDB database server using phpMyAdmin.

PHP Web Programming Video Courses:

Thank you again for using our guide to install phpMyAdmin on Ubuntu 20.04/18.04 / Debian 9 Linux system.

Your support is our everlasting motivation,
that cup of coffee is what keeps us going!

As we continue to grow, we would wish to reach and impact more people who visit and take advantage of the guides we have on our blog. This is a big task for us and we are so far extremely grateful for the kind people who have shown amazing support for our work over the time we have been online.

Thank You for your support as we work to give you the best of guides and articles. Click below to buy us a coffee.


Please enter your comment!
Please enter your name here