How to Install phpMyAdmin with Nginx (LEMP) on Ubuntu 24.04 LTS

This tutorial will be showing you how to install phpMyAdmin with Nginx, MariaDB and PHP8.3 (LEMP) on Ubuntu 24.04. phpMyAdmin is a free and open-source web-based database management tool written in PHP. It provides a graphical web interface for users to manage MySQL or MariaDB database.

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;


To follow this tutorial, you need to have an Ubuntu 24.04 OS running on a remote server.

If you are looking for a virtual private server (VPS), I recommend Kamatera VPS, which features:

  • 30 days free trial.
  • Starts at $4/month (1GB RAM)
  • High-performance KVM-based VPS
  • 9 data centers around the world, including the United States, Canada, UK, Germany, The Netherlands, Hong Kong, and Isreal.

Follow the tutorial linked below to create your Linux VPS server at Kamatera.

It is assumed that you have already installed LEMP stack on Ubuntu 24.04. If not, please check out the following tutorial.

With that out of the way, let’s get started with installing phpMyAdmin.

Step 1: Download phpMyAdmin on Ubuntu 24.04 Server

phpMyAdmin is included in the default Ubuntu 24.04 software repository, but speaking from my experience, it’s better to install the latest version using the upstream package. Run the following command to download it.


Then extract it.

sudo apt install unzip


Move phpMyadmin to /var/www/ directory.

sudo mkdir -p /var/www/

sudo mv phpMyAdmin-*-all-languages /var/www/phpmyadmin

Then make the web server user (www-data) as the owner of this directory.

sudo chown -R www-data:www-data /var/www/phpmyadmin

Step 2: Create a MariaDB Database and User for phpMyAdmin

Log in to MariaDB console.

sudo mysql -u root

Create a new database for phpMyAdmin using the following SQL command. This tutorial names it phpmyadmin, you can use whatever name you like for the database.

CREATE DATABASE phpmyadmin DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

The following SQL command will create the phpmyadmin database user and set a password, and at the same time grant all permission of the new database to the new user so later on phpMyAdmin can write to the database. Replace red texts with your preferred password.

GRANT ALL ON phpmyadmin.* TO 'phpmyadmin'@'localhost' IDENTIFIED BY 'your_preferred_password';

Flush the privileges table and exit the MariaDB console.



Step 3: Install Required and Recommended PHP Modules.

Run the following command to install PHP modules required or recommended by phpMyAdmin.

sudo apt install -y php-imagick php-phpseclib php-php-gettext php8.3-common php8.3-mysql php8.3-fpm php8.3-gd php8.3-imap php8.3-curl php8.3-zip php8.3-xml php8.3-mbstring php8.3-bz2 php8.3-intl php8.3-gmp

Step 4: Create Nginx Server Block for phpMyAdmin

To be able to access the phpMyAdmin web interface, we need to create a Nginx server block by running the following command.

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

We will configure it so that we can access phpMyAdmin via a sub-domain. Paste the following text into the file. Replace with your actual sub-domain and don’t forget to create DNS A record for it.

server {
  listen 80;
  listen [::]:80;
  root /var/www/phpmyadmin/;
  index index.php index.html index.htm index.nginx-debian.html;

  access_log /var/log/nginx/phpmyadmin_access.log;
  error_log /var/log/nginx/phpmyadmin_error.log;

  location / {
    try_files $uri $uri/ /index.php;

  location ~ \.php$ {
    fastcgi_pass unix:/run/php/php8.3-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    include snippets/fastcgi-php.conf;

  location ~ /\.ht {
    deny all;

Your phpMyAdmin files are in /var/www/phpmyadmin/ directory. Save and close the file. Then test Nginx configurations.

sudo nginx -t

If the test is successful, reload Nginx for the changes to take effect.

sudo systemctl reload nginx

Now you should be able to access phpMyAdmin web interface via


Step 5: Installing TLS Certificate

To secure the phpMyadmin web interface, we can install a free Let’s Encrypt TLS certificate. Install the Let’s Encrypt client from Ubuntu 24.04 software repository like below:

sudo apt install certbot python3-certbot-nginx

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

sudo certbot --nginx --agree-tos --redirect --hsts --staple-ocsp -d --email [email protected]


  • –nginx: Use the Nginx authenticator and installer
  • –agree-tos: Agree to Let’s Encrypt terms of service
  • –redirect: Enforce HTTPS by 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 a 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.


Step 6: Create the phpMyAdmin Config File

Copy the example config file.

sudo cp /var/www/phpmyadmin/ /var/www/phpmyadmin/

Now edit the new file.

sudo nano /var/www/phpmyadmin/

Find the following line.

$cfg['blowfish_secret'] = ''; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

We need to enter a 32-bytes long string of random bytes like below.

$cfg['blowfish_secret'] = 'eYU7tk3jmNLYDGYJ9h7AZE2BYXx4UHSQ'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

Save and close the file.

Step 7: Troubleshoot phpMyAdmin Login Error

If you log in 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 log in with user phpmyadmin, you won’t see the above error. However, user phpmyadmin can only be used to administer the phpmyadmin database.

The cause of the error is that by default MariaDB root user is authenticated via the unix_socket plugin, instead of using the mysql_native_password plugin. To get around this issue, we can create another admin user and grant all privileges to the new admin user.

Log into the MariaDB server from the command line.

sudo mariadb -u root

Create an admin user with password authentication.

create user admin@localhost identified by 'your-chosen-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 phpMyAdmin with the admin account and manage all databases.

Step 8: Restricting Access to the /setup Directory

Since the phpMyAdmin setup is finished, there’s no need to allow access to the /setup directory.

Edit Nginx configuration file.

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

Add the following code snippet to this file.

  location ~ ^/(doc|sql|setup)/ {
    deny all;

Save and close the file. Then test Nginx configurations.

sudo nginx -t

If the test is successful, reload Nginx for the changes to take effect.

sudo systemctl reload nginx

TLS Certificate Auto-Renewal

To automatically renew Let’s Encrypt certificate, simply edit root user’s crontab file.

sudo crontab -e

Then add the following line at the bottom.

@daily certbot renew --quiet && systemctl reload nginx

Reloading Nginx is needed for it to pick up the new certificate to clients.

Use Webmin to Manage MySQL/MariaDB Databases

Webmin is a general Linux server admin panel. It also allows you to manage MySQL/MariaDB databases from a graphical user interface, although it’s not as feature-rich as phpMyAdmin when it comes to database management.

  • Create databases
  • Create database users
  • Grant permissions to database users.

How to Install Webmin on Ubuntu Server

Wrapping Up

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

Rate this tutorial
[Total: 7 Average: 5]

16 Responses to “How to Install phpMyAdmin with Nginx (LEMP) on Ubuntu 24.04 LTS

  • ed peterson
    1 week ago

    all good until

    This site can’t be reached refused to connect.

    it’s a firewall issue? I don’t know how the firewall can/should be set,

    I don’t understand what the problem is, any help would be appreciated.. thanks.

    • Xiao Guo-An (Admin)
      1 week ago

      If it’s a firewall issue, try

      sudo apt install ufw
      sudo ufw allow http
      sudo ufw allow https
      sudo ufw enable
    • Xiao Guo-An (Admin)
      1 week ago

      Note that if you are using Amazon EC2, or Google Cloud Platform, you need to set firewall rules in the web-based control panel.

  • Jiří Knotek
    1 month ago

    Thank You for answer. I am linux beginner. I already understand.

  • CheffieCT
    5 months ago

    Excellent article for setting up phpmyadmin. I have followed this to the T and it is working 100%. I need this to work before re-install my nextcloud server at home. The only question I have is that… DO I REALLY have to install phpmyadmin as I dont really know how to use it? I have completed to the certbot part which it is all working.

    • Xiao Guo-An (Admin)
      5 months ago

      phpMyAdmin is for people who don’t want to manage MySQL/MariaDB database from command line. You can follow my NextCloud tutorial without using phpMyAdmin.

  • HenryTheTech
    5 months ago

    When I punch in the IP of my server It connects to NGINX and not phpmyadmin, if using https I get “The site cant be reached” and I am using Chrome.

    everything installed fine and sudo nginx -t is successful

  • HenryTheTech
    5 months ago

    Here’s the answer to my own question. Apparently Ubuntu 18.04 local domain resolution is broken.

    sudo vim /etc/systemd/resolved.conf
    and uncomment and edit Domains:



  • HenryTheTech
    5 months ago

    Sorry, here is the full explanation to fix faulty local DNS resolution in Ubuntu 18:04

    For me working way for Ubuntu 18.04 is:
    Edit avahi conf:

     sudo vim /etc/avahi/avahi-daemon.conf 

    and change .local to .alocal :

     [server] domain-name=.alocal 

    then, open resolved.conf:

     sudo vim /etc/systemd/resolved.conf 

    and uncomment and edit Domains:

     [Resolve] ... Domains=yourdomain.local ... 

    and finally restart services:

     sudo service systemd-resolved restart  
     sudo service avahi-daemon restart 
  • Thank you very very very much! This is the most detailed and easy to follow guide I have found! You helped me a lot! Wish you all the best!!!

  • Thank you for the excellent tutorials! Everything goes well for me up until Step 2 where I try to create an Nginx server block. When I insert my subdomain into the mix, I am unable to reach it. However, when I insert my local IP address everything works. This wouldn’t bother me except for not being able to use Lets Encrypt. Do I need to use the “pma.” prefix?

    • Xiao Guoan (Admin)
      5 months ago

      If you install phpMyAdmin on your local computer, you can use an IP address instead of domain name.

      If you have multiple Nginx server blocks, you can use a fictitious domain name/subdomain instead of IP address, or Nginx will use the default server block.

      You can create a local DNS records in /etc/hosts file on your computer for the fictitious domain name, so your computer can know the IP address.

  • Well done Tuto

  • Johnny Benton
    1 month ago

    Hi Xiao,
    The following lines and SSL path are missing from phpmyadmin.conf file:

    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
  • Jiri Knotek
    1 month ago

    Is “sudo mv phpMyAdmin-*-all-languages /var/www/phpmyadmin” correct?

    • Xiao Guo-An (Admin)
      1 month ago

      Yes, it is correct. The folder phpMyAdmin-5.2.1-all-languages will be moved to /usr/share/ and renamed to phpmyadmin

Leave a Comment

  • Comments with links are moderated by admin before published.
  • Your email address will not be published.
  • Use <pre> ... </pre> HTML tag to quote the output from your terminal/console.
  • Please use the community ( for questions unrelated to this article.
  • I don't have time to answer every question. Making a donation would incentivize me to spend more time answering questions.

The maximum upload file size: 2 MB. You can upload: image. Links to YouTube, Facebook, Twitter and other services inserted in the comment text will be automatically embedded. Drop file here