Site icon System Zone

phpMyAdmin with NGINX – Installation and Configuration

In modern web development, server management is a vital part. Two popular tools that assist in this process are Nginx and phpMyAdmin. Nginx is a high-performance web server, while phpMyAdmin is a widely-used web-based interface for managing MySQL or MariaDB databases. When combined, these tools provide a strong platform for serving dynamic web applications and managing their databases efficiently.

What is Nginx?

NGINX (pronounced “engine-x”) is an open-source web server that also functions as a reverse proxy, load balancer, and HTTP cache. It is known for its speed, reliability and ability to handle a large number of simultaneous connections efficiently, making it ideal for high-traffic websites.

Key Features of Nginx

The key features of NGINX Web Server are –

What is phpMyAdmin?

phpMyAdmin is a free and open-source web application written in PHP that provides an easy-to-use interface to manage MySQL or MariaDB databases. It is a popular choice among developers and administrators for database management tasks, such as querying the database, exporting/importing data, and managing user permissions.

Key Features of phpMyAdmin

The key features of phpMyAdmin are –

Setting Up Nginx with phpMyAdmin

Install Nginx

First, we need to install Nginx on our server. If we are using a Debian-based distribution, we can install Nginx using the following commands.

Once installed, we can start and enable Nginx to run at startup with the following command.

We can check the status of Nginx using the following command.

Install PHP and MariaDB

For phpMyAdmin to function, we need to have PHP and MariaDB installed on our system. To install PHP and MariaDB, we need to run the following command.

Make ensure that both PHP-FPM and MariaDB are configured and running.

MariaDB Configuration

For new MariaDB installations, we need to run security script. The script changes some of the less secure default options and makes it more secure.

To run the security script, we need to run the following command.

This will take us through a series of prompts where we can make some changes to our MariaDB installation’s security options. We can do the following actions for these options.

Enter current password for root (enter for none): Hit Enter because we have no initial password.

Set root password? [Y/n] N

We will now create a new account called dbadmin with the same capabilities as the root account, but configured for password authentication. So, we need to open up the MariaDB prompt from our terminal.

We are now in MariaDB prompt. Do the following Database command to create a user and to change its privileges.

MariaDB is now ready and we can install phpMyAdmin now.

Install phpMyAdmin

To install phpMyAdmin, we need to run the following command.

During the installation, we will be prompted to choose the web server. Since we are using Nginx, we can skip this step by selecting “None” and manually configure it later.

Configure Nginx to Use phpMyAdmin

Once phpMyAdmin is installed, we need to configure Nginx to serve it. First, we need to create a symbolic link from phpMyAdmin’s installation directory to Nginx’s document root.

We can now create a subdomain for phpMyAdmin and a virtual host to access the phpMyAdmin directory or type http://server_ip/phpmyadmin to access phpmyadmin directory directly. Or we can edit the default Nginx configuration file to handle PHP files

and can add the following block within the server block.

location /phpmyadmin {

root /usr/share/;

index index.php index.html index.htm;

location ~ ^/phpmyadmin/(.+\.php)$ {

try_files $uri =404;

fastcgi_pass unix:/run/php/php-fpm.sock;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

}

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

root /usr/share/;

}

}

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

Now if we type our configured URL or http://server_ip/phpmyadmin we will get the following login page of phpMyAdmin.

phpMyAdmin Login Page

Providing our configured username and password, we login to phpMyAdmin web interface and can manage our Databases with phpMyAdmin.

Secure phpMyAdmin (Optional but Recommended)

Securing phpMyAdmin is essential, as it is a common target for attacks. Here are a few steps we can take.

Nginx and phpMyAdmin together offer a powerful solution for managing both web servers and databases. While Nginx takes care to handle web traffic efficiently, phpMyAdmin shortens database management, making it accessible through a web interface. Proper setup and security measures ensure a smooth and secure server environment. Whether we are hosting a small website or a large-scale application, this combination can help us manage our infrastructure effectively.

Exit mobile version