Install phpMyAdmin on Ubuntu 20.04

0
3544

phpMyAdmin is a free and opensource application written in PHP that facilitates the administration and management of MySQL and MariaDB over the Web. In this guide, we are going to learn how to install phpMyAdmin on Ubuntu 20.04.

phpMyAdmin allows administrators to;

  • browse through databases and tables;
  • create, copy, rename, alter and drop databases;
  • create, copy, rename, alter and drop tables;
  • perform table maintenance;
  • add, edit and drop fields;
  • execute any SQL-statement, even multiple queries;
  • create, alter and drop indexes;
  • load text files into tables;
  • create and read dumps of tables or databases;
  • export data to SQL, CSV, XML, Word, Excel, PDF and LaTeX formats;
  • administer multiple servers;
  • manage MySQL users and privileges;
  • check server settings and runtime information with configuration hints;
  • check referential integrity in MyISAM tables;
  • create complex queries using Query-by-example (QBE), automatically
    connecting required tables;
  • create PDF graphics of database layout;
  • search globally in a database or a subset of it;
  • transform stored data into any format using a set of predefined
    functions, such as displaying BLOB-data as image or download-link;
  • manage InnoDB tables and foreign keys;

Install phpMyAdmin on Ubuntu 20.04

Prerequisites

Since phpMyAdmin is a web based tool for administering MySQL or MariaDB, and is written on PHP, the most basic requirement that you need is either a LAMP or LEMP Stack. This demo uses the former.

Install LAMP Stack on Ubuntu 20.04

We have describe extensively how to install LAMP stack on Ubuntu 20.04 in our previous guide whose link is provided below;

Install LAMP Stack on Ubuntu 20.04

Install other required PHP modules for phpMyAdmin;

apt install php7.4-{bz2,json,mbstring,zip,gd,curl,xml,common,opcache,imagick}

See list of requirements on phpMyAdmin requirements page.

Install phpMyAdmin on Ubuntu 20.04

phpMyAdmin 4.4.9 is available on the default Ubuntu 20.04 repos. However the latest stable release version of phpMyAdmin as of this writing is v5.0.2. Hence, to install the latest version, proceed as follows;

Download phpMyAdmin Tarball

Navigate to phpMyAdmin downloads page and grab the source tarball of your preferred language. You can obtain the source tarball link and use wget to pull it. For example, in this guide, we using phpMyAdmin english version. Be sure to replace the version number accordingly.

VER=5.0.2
wget https://files.phpmyadmin.net/phpMyAdmin/$VER/phpMyAdmin-$VER-english.tar.gz

Install phpMyAdmin on Ubuntu 20.04

phpMyAdmin comes bundled as a ready application. By default, phpMyAdmin expects to find its files under /usr/share/phpmyadmin directory. As such, we are going to install it on this directory.

Create this prior to extracting phpMyAdmin.

mkdir /usr/share/phpmyadmin

Extract the source tarball;

tar xzf phpMyAdmin-$VER-english.tar.gz -C /usr/share/phpmyadmin --strip-components=1

Create Apache VirtualHost for phpMyAdmin

Create Apache virtual host configuration file for phpMyAdmin as shown below;

vim /etc/apache2/sites-available/phpmyadmin.conf
Alias /phpmyadmin /usr/share/phpmyadmin

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

    <IfModule mod_php7.c>
        php_admin_value open_basedir /usr/share/phpmyadmin/
    </IfModule>

</Directory>

<Directory /usr/share/phpmyadmin/templates>
    Require all denied
</Directory>
<Directory /usr/share/phpmyadmin/libraries>
    Require all denied
</Directory>

# Enable phpMyAdmin Setup basic Authentication
<Directory /usr/share/phpmyadmin/setup>
    <IfModule mod_authz_core.c>
        <IfModule mod_authn_file.c>
            AuthType Basic
            AuthName "phpMyAdmin Setup"
            AuthUserFile /usr/share/phpmyadmin/.pma.setup
        </IfModule>
        Require valid-user
    </IfModule>
</Directory>

Save and exit the configuration file.

Since we have enabled basic authentication for the setup page, generate username and passwords and store them in the specified auth file. Replace the usernames accordingly;

htpasswd -c /usr/share/phpmyadmin/.pma.setup pmaadmin

Verify Apache configuration syntax;

apachectl -t
Syntax OK

Enable phpMyAdmin site;

a2ensite phpmyadmin.conf

Configure phpMyAdmin on Ubuntu 20.04

Rename the sample phpMyAdmin configuration file;

cp /usr/share/phpmyadmin/config{.sample,}.inc.php

Open the configuration file for modification;

vi /usr/share/phpmyadmin/config.inc.php

Create a blowfish secret required for cookie based authentication to encrypt password in cookie. You can generate the blowfish secret online and paste as follows;

...
/**
 * This is needed for cookie based authentication to encrypt password in
 * cookie. Needs to be 32 chars long.
 */
$cfg['blowfish_secret'] = 'plSW/=Ky24yD4gH2}=},zFn48Vx1rml5'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
...

Save and quit the configuration file.

Restart Apache

systemctl restart apache2

Allow Apache on UFW for external access.

ufw allow 80/tcp

Accessing phpMyAdmin on Ubuntu 20.04

You can now access phpMyAdmin from the browser using the address, http://server-host-name_or_IP/phpmyadmin.

Install phpMyAdmin on Ubuntu 20.04

Login using your database root user credentials.

If you get the error below; then you need to change the default MySQL socket authentication plugin to mysql native password as described in our guide on installing MySQL 8 on Ubuntu 20.04.

Install phpMyAdmin on Ubuntu 20.04

Upon successful login, you get to phpMyAdmin dashboard.

Install phpMyAdmin on Ubuntu 20.04

You have successfully installed and setup phpMyAdmin on Ubuntu 20.04. You can now be able to administer your MySQL or MariaDB from web.

Related Tutorials

Install phpMyAdmin with Nginx on Debian 10 Buster

Install phpMyAdmin on Debian 10 Buster

Install phpMyAdmin with Nginx on Fedora 30

Install phpMyAdmin with Apache on Fedora 30

LEAVE A REPLY

Please enter your comment!
Please enter your name here