(Last Updated On: May 2, 2019)

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

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-get install -y php php-tcpdf php-cgi php-mysqli php-pear php-mbstring php-gettext libapache2-mod-php php-common php-phpseclib php-mysql

If you want to use PHP 7.3 instead, refer to our guides below for the installation.

How to Install PHP 7.3 on Debian 9 / Debian 8

How to install PHP 7.3 on Ubuntu 18.04 / Ubuntu 16.04

Step 2: Install MariaDB Database Server

The next step is to install MariaDB database server. We already have comprehensive guides on this subject.

How to Install MariaDB 10.x on Debian 9 / Debian 8

Install MariaDB 10.x on Ubuntu 18.04

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 and Install latest phpMyAdmin on Ubuntu 18.04 / Debian 9

Visit phpMyAdmin downloads page and check the latest available package. As of this writing, this is version 4.8.5.

export VER="4.8.5"
sudo apt-get install -y wget
cd /tmp
wget https://files.phpmyadmin.net/phpMyAdmin/${VER}/phpMyAdmin-${VER}-all-languages.tar.gz

For English language only package, use:

cd /tmp
wget https://files.phpmyadmin.net/phpMyAdmin/${VER}/phpMyAdmin-${VER}-english.tar.gz

Extract downloaded Archive

tar xvf phpMyAdmin-${VER}-english.tar.gz

OR
tar xvf phpMyAdmin-${VER}-all-languages.tar.gz

Delete compressed file and move the resulting folder to /usr/share/phpmyadmin folder.

rm *.tar.gz
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/config.sample.inc.php  /usr/share/phpmyadmin/config.inc.php

Edit the file and ser secret passphrase:

$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

Add below data:

# phpMyAdmin default Apache configuration

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
        </IfModule>
        <FilesMatch ".+\.php$">
            SetHandler application/x-httpd-php
        </FilesMatch>

        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>
    <IfModule mod_php.c>
        <IfModule mod_mime.c>
            AddType application/x-httpd-php .php
        </IfModule>
        <FilesMatch ".+\.php$">
            SetHandler application/x-httpd-php
        </FilesMatch>

        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>

</Directory>

# 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
        </IfModule>
        Require valid-user
    </IfModule>
</Directory>

# Disallow web access to directories that don't need it
<Directory /usr/share/phpmyadmin/templates>
    Require all denied
</Directory>
<Directory /usr/share/phpmyadmin/libraries>
    Require all denied
</Directory>
<Directory /usr/share/phpmyadmin/setup/lib>
    Require all denied
</Directory>

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

Require ip 127.0.0.1 192.168.18.0/24

Step 5: Visit phpMyAdmin Web interface

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

Enjoy Administering MySQL / MariaDB database server using phpMyAdmin.