How to Install PHPMyAdmin with Nginx on Ubuntu 22.04

In this tutorial, i am going to show you how to install and use PHPMyAdmin with Nginx on linux ubuntu 22.04.

How to Install PHPMyAdmin with Nginx on Ubuntu 22.04

Follow the following steps to install and use PHPMyAdmin with Nginx on ubuntu 22.04 system:

  • Step 1 – Update System Dependencies
  • Step 2 – Install PHPMyAdmin
  • Step 3 – Configure phpMyAdmin with Nginx
  • Step 4 – Restart Web Server
  • Step 5 – Test the Installation of PHPMyAdmin

Step 1 – Update System Dependencies

Run the following command on the command line to update system dependencies:

sudo apt update

Step 2 – Install PHPMyAdmin

Run the following command on the command line to install phpMyAdmin with nginx on ubuntu 22.04:

sudo apt install phpmyadmin

Once the PHPMyAdmin installation has been done, then open a prompt to choose web server, press TAB to skip this.

When prompted again to allow dbconfig-common to install a database and configure select Yes and press ENTER.

Then type and confirm a password or allow to use any random password.

Step 3 – Configure phpMyAdmin with Nginx

Now, configure PHPMyAdmin with Nginx by creating a symbolic link.

Use the following command to create a new configuration for phpMyAdmin:

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

Add the following to the new file. Make sure, use the correct PHP version:

location /phpmyadmin {
    root /usr/share/;
    index index.php index.html index.htm;
    location ~ ^/phpmyadmin/(.+\.php)$ {
        try_files $uri =404;
        root /usr/share/;
        fastcgi_pass unix:/run/php/php8.0-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include /etc/nginx/fastcgi_params;
    }

    location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
        root /usr/share/;
    }
}

Save the file and exit.

Then, add the new file inside the server block from where wish to access phpMyAdmin.

Edit server block configuration which will be located inside /etc/nginx/sites-available and include the snippet so configuration looks something similar to the one below.

server {
    . . .

    include snippets/phpmyadmin.conf;

    . . .
}

Step 4 – Restart Web Server

Run the following command on command line to restart Nginx for the changes to take effect:

sudo service nginx restart

Step 5 – Test the Installation of PHPMyAdmin

Access phpMyAdmin using domain followed by /phpmyadmin.

https://domain.com/phpmyadmin

Conclusion

In this tutorial, i have shown to you how to install phpMyAdmin on Ubuntu 20.04 with Nginx.

More Tutorials

Leave a Comment