How To Install phpMyAdmin with Nginx on Ubuntu 20.04 | Holhol24


phpMyAdmin is a free and open-source web interface for managing
MySQL and
MariaDB servers. It is widely used by web hosting companies to enable website owners to create and manage databases on their own.

phpMyAdmin helps us to perform database activities such as creating, deleting, querying, database, tables, columns, etc.

In this post, we will see how to install
phpMyAdmin with Nginx on
Ubuntu 20.04.


Install MariaDB Server

To manage databases with phpMyAdmin, your system must have a database instance running and the
Nginx web server.

Standalone Database

Follow the below tutorials and prepare your system for setting up phpMyAdmin.

Step 1:
How To Install MariaDB on Ubuntu 20.04


Step 1:
How To Install MySQL 8.0 on Ubuntu 20.04


Step 2:
How To Install LEMP Stack on Ubuntu 20.04

You can skip the installation of the MariaDB server in Step 2 – LEMP stack tutorial if you have followed Step 1 – MariaDB/MySQL installation.

Install the below PHP extensions for phpMyAdmin to connect with the database.

sudo apt install -y php-json php-mbstring

LEMP Stack

How To Install LEMP Stack on Ubuntu 20.04

Install the below PHP extensions for phpMyAdmin to connect with the database.

sudo apt install -y php-json php-mbstring

Install phpMyAdmin

The phpMyAdmin available in the Ubuntu OS repository for Ubuntu 20.04 is a bit old. So, we will download the latest version of phpMyAdmin from the
official website.


Extract phpMyAdmin using the
tar command.

tar -zxvf phpMyAdmin-5.0.2-all-languages.tar.gz

Move the phpMyAdmin to your desired location.

sudo mv phpMyAdmin-5.0.2-all-languages /usr/share/phpMyAdmin

Configure phpMyAdmin

Copy the sample configuration file.

sudo cp -pr /usr/share/phpMyAdmin/ /usr/share/phpMyAdmin/

Edit the configuration file.

sudo nano /usr/share/phpMyAdmin/

Generate a
blowfish secret code and update the secret in the configuration file.

$cfg['blowfish_secret'] = 'CfX1la/aG83gx1{7rADus,iqz8RzeV8x'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

Also, uncomment the phpMyAdmin storage settings.

Change the controluser and controlpass with your user and password who have access to phpMyAdmin’s configuration database which we will create in the next step. This user account is used to access phpMyAdmin configuration storage.

 * phpMyAdmin configuration storage settings.

/* User used to manipulate with storage */
$cfg['Servers'][$i]['controlhost'] = 'localhost';
// $cfg['Servers'][$i]['controlport'] = '';
$cfg['Servers'][$i]['controluser'] = 'pma';
$cfg['Servers'][$i]['controlpass'] = 'pmapass';

/* Storage database and tables */
$cfg['Servers'][$i]['pmadb'] = 'phpmyadmin';
$cfg['Servers'][$i]['bookmarktable'] = 'pma__bookmark';
$cfg['Servers'][$i]['relation'] = 'pma__relation';
$cfg['Servers'][$i]['table_info'] = 'pma__table_info';
$cfg['Servers'][$i]['table_coords'] = 'pma__table_coords';
$cfg['Servers'][$i]['pdf_pages'] = 'pma__pdf_pages';
$cfg['Servers'][$i]['column_info'] = 'pma__column_info';
$cfg['Servers'][$i]['history'] = 'pma__history';
$cfg['Servers'][$i]['table_uiprefs'] = 'pma__table_uiprefs';
$cfg['Servers'][$i]['tracking'] = 'pma__tracking';
$cfg['Servers'][$i]['userconfig'] = 'pma__userconfig';
$cfg['Servers'][$i]['recent'] = 'pma__recent';
$cfg['Servers'][$i]['favorite'] = 'pma__favorite';
$cfg['Servers'][$i]['users'] = 'pma__users';
$cfg['Servers'][$i]['usergroups'] = 'pma__usergroups';
$cfg['Servers'][$i]['navigationhiding'] = 'pma__navigationhiding';
$cfg['Servers'][$i]['savedsearches'] = 'pma__savedsearches';
$cfg['Servers'][$i]['central_columns'] = 'pma__central_columns';
$cfg['Servers'][$i]['designer_settings'] = 'pma__designer_settings';
$cfg['Servers'][$i]['export_templates'] = 'pma__export_templates';


Import the create_tables.sql to create tables for phpMyAdmin.

sudo mysql 

Login to MariaDB.

sudo mysql -u root -p

Add the user and grant permission to phpMyAdmin’s configuration database.

CREATE USER 'pma'@'localhost' IDENTIFIED BY 'pmapass';

GRANT ALL ON phpmyadmin.* TO 'pma'@'localhost';



Create a virtual host configuration file for phpMyAdmin under the /etc/nginx/conf.d directory.

sudo nano /etc/nginx/conf.d/phpMyAdmin.conf

Use the following server block to create a virtual host for phpMyAdmin. Change the domain name (server_name) as per your requirement.

server {
   listen 80;
   server_name pma.holhol24.local;
   root /usr/share/phpMyAdmin;

   location / {
      index index.php;

## Images and static content is treated different
   location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
      access_log off;
      expires 30d;

   location ~ /.ht {
      deny all;

   location ~ /(libraries|setup/frames|setup/libs) {
      deny all;
      return 404;

   location ~ .php$ {
      include /etc/nginx/fastcgi_params;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME /usr/share/phpMyAdmin$fastcgi_script_name;

Create a tmp directory for phpMyAdmin and then change the permission.

sudo mkdir /usr/share/phpMyAdmin/tmp

sudo chmod 777 /usr/share/phpMyAdmin/tmp

Set the ownership of the phpMyAdmin directory.

sudo chown -R www-data:www-data /usr/share/phpMyAdmin

Restart the services.

sudo systemctl restart nginx

sudo systemctl restart php7.4-fpm

Create DB Admin User

By default, MariaDB root user is allowed to log in only via the Unix socket. So, we will now create a database administrative user with permission to manage all databases.

GRANT ALL PRIVILEGES ON *.* TO 'dbadmin'@'localhost' IDENTIFIED BY 'password';



If required, you can
disable Unix socket authentication for MariaDB root user and enable native password login.

Access phpMyAdmin

Access the phpMyAdmin using the
web browser:


Log in with database admin user we just created in the previous step.

Login to phpMyAdmin

You will get the home page where you can manage databases.

phpMyAdmin Home Page
phpMyAdmin Home Page


That’s All. I hope this post helped you to install
phpMyAdmin with
Nginx on
Ubuntu 20.04. Please share your feedback in the comments section.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More