Amazon Prime offer
You are currently viewing phpMyAdmin with NGINX – Installation and Configuration

phpMyAdmin with NGINX – Installation and Configuration

Integrating Nginx and phpMyAdmin for Efficient Server and Database Management

In today’s web development landscape, managing servers effectively is essential. Among the popular tools that aid in this area are Nginx and phpMyAdmin. Nginx functions as a high-performance web server, while phpMyAdmin provides a web-based interface for managing MySQL or MariaDB databases. When used together, these tools offer an effective setup for serving dynamic websites and simplifying database administration.

Understanding Nginx

NGINX (pronounced “engine-x”) is an open-source web server recognized for its capability to also serve as a reverse proxy, load balancer, and HTTP cache. Known for its speed and reliability, Nginx can handle a significant volume of connections concurrently, making it ideal for sites with heavy traffic.

Key Features of Nginx

  • Event-Driven Architecture: Nginx processes requests asynchronously, which allows it to handle numerous connections without overloading the system resources.
  • Reverse Proxy and Load Balancing: Nginx can distribute traffic across multiple servers, ensuring no single server becomes a bottleneck.
  • Optimized Static Content Delivery: Efficiently handles static files (e.g., images, CSS), which contributes to faster page load times.
  • Security: Offers features such as SSL/TLS encryption, HTTP/2 support, and DDoS protection.
  • Scalability: Easily adapts to increased traffic by balancing the load across multiple servers.

Download Free EBook

Introducing phpMyAdmin

phpMyAdmin is an open-source, web-based application written in PHP that facilitates managing MySQL and MariaDB databases. This tool is particularly popular for its intuitive interface, enabling database tasks such as querying, importing/exporting data, and managing permissions without complex commands.

Key Features of phpMyAdmin

  • Web-Based Access: Accessible from any browser, eliminating the need for additional software installations.
  • Comprehensive Database Management: Supports creating, modifying, and deleting databases and tables.
  • Query Execution: Offers the capability to execute SQL queries directly within the interface.
  • Data Import/Export: Allows exporting data in formats like CSV or SQL and reimporting it as needed.
  • User Privilege Management: Administrators can assign or revoke permissions, enhancing database security.

Setting Up Nginx and phpMyAdmin on a Server

Step 1: Install Nginx

To begin, Nginx must be installed. On a Debian-based system, this can be achieved by running:

sudo apt update
sudo apt install nginx

Start and enable Nginx to launch at startup:

sudo systemctl start nginx
sudo systemctl enable nginx

Check its status using:

sudo systemctl status nginx

Step 2: Install PHP and MariaDB

To support phpMyAdmin, install PHP and MariaDB:

sudo apt install php-fpm php-mysql mariadb-server

Ensure both PHP-FPM and MariaDB are correctly configured and operational.

Step 3: Configure MariaDB

After installing MariaDB, increase security by running:

sudo mysql_secure_installation

Follow the prompts, setting security configurations as desired. Then, create a user account with administrative rights:

CREATE USER 'dbadmin'@'localhost' IDENTIFIED BY 'db@password';
GRANT ALL PRIVILEGES ON *.* TO 'dbadmin'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES; EXIT;

Step 4: Install phpMyAdmin

Install phpMyAdmin Ubuntu 22.04 Nginx digitalocean

To install phpMyAdmin, run:

sudo apt install phpmyadmin

During installation, select “None” for the web server option since we’ll configure it manually for Nginx.

Step 5: Configure Nginx to Serve phpMyAdmin

To serve phpMyAdmin through Nginx, create a symbolic link:

sudo ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin

Then, edit the default Nginx configuration file to add phpMyAdmin settings:

sudo vim /etc/nginx/sites-available/default

Within the server block, add:

nginx

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 the changes and restart Nginx:

sudo systemctl restart nginx

phpMyAdmin can now be accessed via http://server_ip/phpmyadmin.

Securing phpMyAdmin (Recommended)

Securing phpMyAdmin is crucial, as it’s often a target for attacks. Recommended steps include:

  • Obscure URL: Change the default phpMyAdmin URL for added security.
  • Enable HTTPS: Use SSL certificates from providers like Let’s Encrypt to secure communication.
  • Restrict Access: Limit phpMyAdmin access based on IP addresses or by adding an additional authentication layer.

Conclusion

The combination of Nginx and phpMyAdmin offers a robust solution for managing web traffic and databases. While Nginx efficiently handles server requests, phpMyAdmin makes database management accessible and straightforward. Proper configuration and security measures help create a stable and secure environment, whether hosting a personal site or a high-traffic web application

 

Related Post

NEtwork tools
Helpdesk software free