How to Install phpMyAdmin with Apache 0 0

Last updated on Sep 11, 2019 21:59 in IT » DigitalOcean
Posted ByImron, A.Md

Step 1: Download and Install phpMyAdmin on Ubuntu 18.04

phpMyAdmin is included in Ubuntu 18.04 software repository. so we can easily install it with the command below.

sudo apt update
sudo apt install phpmyadmin

The above command will install all necessary dependencies including PHP7 extensions. During the installation, it will prompt you to select a web server to configure. Hit the space bar to select apache2. (An asterisk indicates the item is selected). Then hit Tab key and Enter to confirm your choice.

phpmyadmin lamp

In the next screen, select Yes to configure a database for phpMyAdmin with dbconfig-common.

phpmyadmin apache config

Then set a password for the phpmyadmin user in MariaDB/MySQL.

install phpmyadmin ubuntu 18.04 apache2

Once this step is done, a new database named phpmyadmin is created and the database user phpmyadmin has necessary privileges to manage this database. If you are curious as I am, you can log into MariaDB and check what privileges phpmyadmin user has been granted.

You can use the following command to log into MariaDB server.

sudo mysql -u root

Then check the privileges of phpmyadmin user.

show grants for phpmyadmin@localhost;


phpmyadmin database configuration

As you can see, user phpmyadmin has all privileges on database phpmyadmin. Now you can exit by executing:


Step 2: Accessing phpMyAdmin from a Sub-directory

When installing phpMyAdmin, a configuration file is placed at /etc/apache2/conf-enabled/phpmyadmin.conf, which allows us to access phpMyAdmin via sub-directory. If you have installed other web applications like WordPress on the same Ubuntu 18.04 server, then simply add /phpmyadmin after your domain name in the browser address bar.

phpmyadmin ubuntu

If phpMyAdmin is installed on your local Ubuntu computer, then you can access phpMyAdmin web interface by typing in the following text in the browser address bar.


If the connection is refused or failed to complete, there might be a firewall preventing HTTP requests. If you are using iptables firewall, then you need to run the following command to open TCP port 80 and 443.

sudo iptables -I INPUT -p tcp --dport 80 -j ACCEPT
sudo iptables -I INPUT -p tcp --dport 443 -j ACCEPT

If you are using UFW firewall, then run this command to open TCP port 80 and 443.

sudo ufw allow http
sudo ufw allow https

Now You can use MariaDB/MySQL username and password to log into phpMyAdmin

Step 3: Access phpMyAdmin From a Sub-domain

If your Ubuntu 18.04 server doesn’t have other Apache virtual host, then you may want to use a sub-domain to access phpMyAdmin web interface. This way, you can enable HTTPS to encrypt the traffic.

First, we need to create an Apache virtual host for phpMyAdmin. The existing phpMyAdmin configuration snippet can be used as a template. Let’s copy it to a new file.

sudo cp /etc/apache2/conf-enabled/phpmyadmin.conf /etc/apache2/sites-available/phpmyadmin.conf

Then edit the new file with a command line text editor, such as Nano.

sudo nano /etc/apache2/sites-available/phpmyadmin.conf

Add the following lines at the beginning of this file. Replace with your preferred sub-domain for phpMyAdmin. Don’t forget to create DNS A record for this sub-domain.

    DocumentRoot /usr/share/phpmyadmin

    ErrorLog ${APACHE_LOG_DIR}/pma.error.log
    CustomLog ${APACHE_LOG_DIR}/pma.access.log combined

Add the following line at the end of this file.

Save and close the file. (To save a file in Nano text editor, press Ctrl+O, then press Enter to confirm. To exit, press Ctrl+X.) Then enable this virtual host.

sudo a2ensite phpmyadmin.conf

Reload Apache web server for this change to take effect.

sudo systemctl reload apache2

Now you should be able to access phpMyAdmin web interface via

how to install phpmyadmin in lubuntu

Before entering user credentials in the login form, let’s enable HTTPS.

Step 4: Enable HTTPS on phpMyAdmin with Apache

To secure the phpMyadmin web interface, we can install a free Let’s Encrypt TLS certificate. Run the following command to install the Let’s Encrypt client (certbot) from Ubuntu 18.04 software repository.

sudo apt install certbot python3-certbot-apache

Python3-certbot-apache is the Apache plugin for Certbot. Now run the following command to obtain and install TLS certificate.

sudo certbot --apache --agree-tos --redirect --hsts --staple-ocsp --must-staple -d --email


  • –apache: Use the Apache authenticator and installer
  • –agree-tos: Agree to Let’s Encrypt terms of service
  • –redirect: Add 301 redirect.
  • –hsts: Add the Strict-Transport-Security header to every HTTP response.
  • –staple-ocsp: Enables OCSP Stapling.
  • –must-staple: Adds the OCSP Must Staple extension to the certificate.
  • -d flag is followed by a list of domain names, separated by comma. You can add up to 100 domain names.
  • –email: Email used for registration and recovery contact.

You will be asked if you want to receive emails from EFF(Electronic Frontier Foundation). After choosing Y or N, your TLS certificate will be automatically obtained and configured for you, which is indicated by the message below.

ubuntu 18.04 phpmyadmin apache subdomain config

Step 5: Troubleshoot phpMyAdmin Login Error

If you try to login to phpMyAdmin with MariaDB root account, you may see the following error.

#1698 - Access denied for user 'root '@'localhost'


mysqli_real_connect(): (HY000/1698): Access denied for user 'root '@'localhost'

If you login with user phpmyadmin, you won’t see the above error. However, user phpmyadmin can only be used to manage the phpmyadmin database. The cause of the error is that by default MariDB root user is authenticated via the unix_socket plugin, instead of using the mysql_native_password plugin. To solve this problem, we can create another admin user and grant all privileges to the new admin user.

Log into MariaDB server from the command line.

sudo mysql -u root

Create an admin user with password authentication.

create user admin@localhost identified by 'your-preferred-password';

Grant all privileges on all databases.

grant all privileges on *.* to admin@localhost with grant option;

Flush privileges and exit;

flush privileges;


Now you can log into phpMyAmin with the admin account and manage all databases.

mysqli_real_connect HY0001698 Access denied for user 'root '@'localhost'

Step 6: Install Latest Stable Version of phpMyAdmin

Ubuntu 18.04 repository ships with PHP7.2 and phpMyAdmin 4.6.6. You can check your phpMyAdmin version in the browser title bar.

ubuntu 18.04 apache phpmyadmin 4.9

However, PHP7.2 is supported by phpMyAdmin since version 4.7.4. When you use phpMyAdmin 4.6.6 with PHP7.2, you will see the following warning message in the Export and Import tab.

parameter must be an array or an object that implements countable

parameter must be an array or an object that implements countable

To fix the compatibility problem, we can install phpMyAdmin 4.9, which is the latest stable version as of this writing. Download it by using wget.


Hint: You can always use the above URL format to download the latest stable version of phpMyAdmin. Simply replace with the latest version number.

Then extract it.

sudo apt install unzip


Back up original phpMyAdmin files.

sudo mv /usr/share/phpmyadmin /usr/share/phpmyadmin-original

Move phpMyadmin 4.9 to /usr/share/phpmyadmin/ directory.

sudo mv phpMyAdmin- /usr/share/phpmyadmin

Edit the vendor config file.

sudo nano /usr/share/phpmyadmin/libraries/vendor_config.php

Find the following line.

define('CONFIG_DIR', '');

Change it to

define('CONFIG_DIR', '/etc/phpmyadmin/');

Save and close the file. Then create the tmp folder to store cache files.

sudo mkdir /usr/share/phpmyadmin/tmp

Change user ownership and group ownership to www-data.

sudo chown www-data:www-data /usr/share/phpmyadmin/tmp

Now you can use phpMyAdmin 4.9 without seeing the PHP errors.

phpmyadmin latest version ubuntu 18.04 apache

Enable Two-Factor Authentication

You can also harden phpMyAdmin by enabling two-factor authentication, which is a feature added in version 4.8. To enable it, log into phpMyAdmin. Then go to Settings -> Two-factor authentication and select Authentication application (2FA).

secure phpmyadmin

After clicking the Configure two-factor authentication button, you will be presented with a QR code, which you need to scan with a two-factor authentication app on your phone.

configure two factor authentication phpmyadmin

Google Authenticator is a popular 2FA app, but I recommend FreeOTP, which is an open-source 2FA app developed by Red Hat. Once you enter the authentication code generated by your 2FA app, two-factor authentication is enabled. If you now log out and log back in, you need to enter the authentication code in addition to username and password.

secure phpmyadmin

Wrapping Up

I hope this tutorial helped you install phpMyAdmin with LAMP on Ubuntu 18.04. As always, if you found this post useful, then subscribe to our free newsletter to get more tips and tricks. Take care 🙂


** The time is base on America/New_York timezone