CentOSLinuxTutorialsUbuntu

How To Install phpMyAdmin on Nginx

Install phpMyAdmin on Nginx

In this tutorial, we will show you how to install phpMyAdmin on Nginx. For those of you who didn’t know, phpMyAdmin is the web-based administration tool for managing the MySQL, MariaDB, and Drizzle servers, it helps in performing database activities such as creating, deleting, querying, tables, columns, relations, indexes, users, permissions, etc.

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.

Prerequisites

  • A server running one of the following operating systems: CentOS or RHEL-based.
  • 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).
  • An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies for Nginx and phpMyAdmin.
  • 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 on Nginx

Step 1. Before proceeding, update your operating system to make sure all existing packages are up to date. Use this command to update the server packages:

sudo dnf upgrade
sudo dnf update

Step 2. Installing PHP and Required PHP Extensions.

phpMyAdmin is a PHP-based web application, so you’ll need to install PHP and some required PHP extensions on your server. You can install PHP and the required extensions by running the following command:

sudo dnf install php php-mysqlnd php-json php-gd php-mbstring

Step 3. Installing Nginx.

By default, the Nginx package comes in the default CentOS repository. Now run the following command below to install Nginx to your CentOS system:

sudo dnf install nginx

After the installation is complete, start the Nginx service and enable it to start automatically on boot by running the following commands:

sudo systemctl start nginx
sudo systemctl enable nginx

For additional resources on installing Nginx, read the post below:

Step 4. Configure Nginx for phpMyAdmin.

By default, Nginx serves files from the /usr/share/nginx/html directory. However, we want to serve phpMyAdmin from a different location. To do this, create a new Nginx configuration file for phpMyAdmin with the following command:

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

Add the following configuration to the file:

server {
    listen       80;
    server_name  your-domain.com;
    root         /usr/share/phpMyAdmin;
    index        index.php;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass unix:/run/php-fpm/www.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

Save and close the file.

Step 5. Download and Install phpMyAdmin.

Now we download the latest version of phpMyAdmin from the official website:

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

Next, extract the archive to /usr/share/phpMyAdmin:

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

Step 6. Configure phpMyAdmin.

Now that you have installed phpMyAdmin, it’s time to configure it for use. Start by editing the configuration file:

nano /etc/phpMyAdmin/config.inc.php

Make the following changes to the file:

$cfg['blowfish_secret'] = 'your_secret_key';

Replace your_secret_key with your own unique random string. This value will be used to encrypt the cookies used by phpMyAdmin.

Next, uncomment the following line and change localhost to the IP address of your MySQL server, like so:

$cfg['Servers'][$i]['host'] = '192.168.77.21';

Save and close the file, then restart the Nginx service for the changes to take effect:

sudo systemctl restart nginx

Step 7. Accessing phpMyAdmin Web UI.

Now open your browser and surf to http://your-ip-address/phpMyAdmin and Log in with the MySQL username and password you set up earlier, and you should be taken to the phpMyAdmin home page, where you can manage your MySQL databases and perform various tasks.

Install phpMyAdmin on Nginx

Congratulations! You have successfully installed phpMyAdmin. Thanks for using this tutorial for installing the phpMyAdmin with the Nginx web server on the Linux system. For additional help or useful information, we recommend you check the official phpMyAdmin website.

Nginx 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 “Nginx 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