UbuntuUbuntu Based

How To Install phpMyAdmin with Nginx on Ubuntu 22.04 LTS

Install phpMyAdmin with Nginx on Ubuntu 22.04

In this tutorial, we will show you how to install phpMyAdmin with Nginx on Ubuntu 22.04 LTS. For those of you who didn’t know, phpMyAdmin is a free web-based management tool for managing the MySQL and MariaDB database servers. With phpMyAdmin, you can perform several tasks, manage user accounts and privileges, import and export data, execute SQL statements, and much more.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the phpMyAdmin with Nginx on Ubuntu 22.04 (Jammy Jellyfish). You can follow the same instructions for Ubuntu 22.04 and any other Debian-based distribution like Linux Mint, Elementary OS, Pop!_OS, and more as well.

Prerequisites

  • A server running one of the following operating systems: Ubuntu 22.04, 20.04, and any other Debian-based distribution like Linux Mint.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install phpMyAdmin with Nginx on Ubuntu 22.04 LTS Jammy Jellyfish

Step 1. First, make sure that all your system packages are up-to-date by running the following apt commands in the terminal.

sudo apt update
sudo apt upgrade
sudo apt install lsb-release ca-certificates apt-transport-https software-properties-common

Step 2. Installing LEMP Stack on Ubuntu.

Before starting this tutorial, the LEMP server must be installed on your server. If you do not have LEMP Stack installed, you can follow our guide here.

Step 3. Installing phpMyAdmin on Ubuntu 22.04.

By default, the phpMyAdmin is not available on Ubuntu 22.04 base repository. Now run the following command below to install the latest version of phpMyAdmin to your Ubuntu system:

wget https://files.phpmyadmin.net/phpMyAdmin/5.2.0/phpMyAdmin-5.2.0-all-languages.tar.gz

Next, extract phpMyAdmin using the tar command:

tar -zxvf phpMyAdmin-5.2.0-all-languages.tar.gz
sudo mv phpMyAdmin-5.2.0-all-languages /usr/share/phpMyAdmin

Step 4. Configure phpMyAdmin.

Now we rename the phpMyAdmin’s sample configuration file for configuring the phpMyAdmin:

sudo mv /usr/share/phpMyAdmin/config.sample.inc.php /usr/share/phpMyAdmin/config.inc.php

Then, edit the configuration file:

sudo nano /usr/share/phpMyAdmin/config.inc.php

Next, generate a blowfish secret and update the below line with the generated secret in the configuration file:

$cfg['blowfish_secret'] = '0};Ow}n{nM80t[C/qhA0bpnYhS;Ey4L='; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

You may also need to uncomment the phpMyAdmin storage settings:

/**
 * phpMyAdmin configuration storage settings.
 */

/* User used to manipulate with storage */
$cfg['Servers'][$i]['controlhost'] = 'localhost';
// $cfg['Servers'][$i]['controlport'] = '';
$cfg['Servers'][$i]['controluser'] = 'ngadimin';
$cfg['Servers'][$i]['controlpass'] = 'your-strong-passwd';

Step 5. Configure Database phpMyAdmin.

phpMyAdmin requires database tables. So, import the create_tables.sql comes with the phpMyAdmin archive package to create tables for phpMyAdmin:

sudo mysql < /usr/share/phpMyAdmin/sql/create_tables.sql -u root -p

Next, we will need to log in to the MariaDB console using the following command:

mysql -u root -p

This will prompt you for a password, so enter your MariaDB root password and hit Enter. Once you are logged in to your database server you need to create a database for phpMyAdmin installation:

MariaDB [(none)]> CREATE USER 'ngadimin'@'localhost' IDENTIFIED BY 'your-strong-passwd';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON phpmyadmin.* TO 'ngadimin'@'localhost' WITH GRANT OPTION;
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

Step 6. Configuring phpMyAdmin for Nginx Support.

Run the commands below to create a phpMyAdmin snippet that can be used on an existing server block:

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

Add the following files:

server {
   listen 80;
   server_name your-domain;
   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_pass unix:/run/php/php8.1-fpm.sock;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
   }
}

Save and close the file, then restart the Nginx web server so that the changes take place:

nginx -tsudo systemctl restart nginx
sudo systemctl restart php8.1-fpm

Then, create a tmp directory for phpMyAdmin and then change the permission:

sudo mkdir /usr/share/phpMyAdmin/tmp
sudo chmod 777 /usr/share/phpMyAdmin/tmp

We will need to change some folders permissions:

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

Step 7. Configure Firewall.

Ubuntu 22.04 has ufw a firewall running by default. Enable connection through ports 80 HTTP and 443 HTTPS:

sudo ufw allow 'Nginx FULL'
sudo ufw enable
sudo ufw status

Step 8. Accessing phpMyAdmin Web Interface.

Once successfully installed, open your web browser and type the URL http://your-domain.com. You will be redirected to the phpMyAdmin login page:

Install phpMyAdmin with Nginx on Ubuntu 22.04 LTS Jammy Jellyfish

Log in with the database user, You should see the phpMyAdmin default dashboard on the following page:

Install phpMyAdmin with Nginx on Ubuntu 22.04 LTS

Step 9. Secure phpMyAdmin with Let’s Encrypt SSL Free Certificate.

First, install Certbot on Ubuntu 22.04 using the following command:

sudo apt install python3-certbot-nginx

Then, set up Certbot for Nginx using the following command:

sudo certbot --nginx --agree-tos --redirect --hsts --staple-ocsp --email you@your-domain.com -d www.your-domain.com

Let’s Encrypt certificates have 90 days of validity, and it is highly advisable to renew the certificates before they expire. To test that this renewal process is working correctly, you can run:

sudo certbot renew --dry-run

Congratulations! You have successfully installed phpMyAdmin. Thanks for using this tutorial for installing the phpMyAdmin database management on Ubuntu 22.04 LTS Jammy Jellyfish system. For additional help or useful information, we recommend you check the official phpMyAdmin website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button