Section 18: phpMyAdmin Installation & Log Rotation Management
This comprehensive guide covers the installation and secure configuration of phpMyAdmin on your NGINX server, along with implementing proper log rotation policies to prevent disk space issues. These procedures are essential for maintaining a secure, efficient, and well-managed server environment.
First, we'll generate secure random passwords for database access:
Access MySQL and create a privileged user for phpMyAdmin:
Test and reload NGINX to ensure proper operation:
Navigate to the NGINX includes directory and create an encrypted password:
Store the username and encrypted password:
Update package lists and install phpMyAdmin:
For security, create a symbolic link with a random, hard-to-guess path:
Create a configuration file with multi-layered security:
Four layers of security protect your phpMyAdmin installation
your_IP_ADDRESS with your actual IP address. To find
your current IP when logged into the server, use: last -n3
Add the phpMyAdmin configuration to your main NGINX configuration:
Add this line inside the server block:
http://server_ip/V2th1pchBI71/
Your server uses log files to record all activity, from login attempts to file serving operations. Without proper management, these logs will grow indefinitely and eventually consume all available disk space, causing your server to crash. Log rotation is the automated process of managing these files through rotation, compression, and deletion.
| Without Log Rotation | With Log Rotation |
|---|---|
| โ Logs grow continuously | โ Logs are rotated daily |
| โ Disk space fills up | โ Old logs are compressed |
| โ Server crashes | โ Logs deleted after 7 days |
| โ Difficult to find recent logs | โ Organized and manageable |
Navigate to the configuration directory:
Create a backup before making changes:
Edit the main configuration file:
Navigate to the service-specific configurations:
You'll see individual configuration files for various services. We'll modify these key files:
| Service | Purpose | Recommended Settings |
|---|---|---|
| fail2ban | Security log for blocked IPs | daily, rotate 3 |
| nginx | Web server access and error logs | daily, rotate 3 |
| rsyslog | System logging daemon | daily, rotate 3 |
| ufw | Firewall logs | daily, rotate 3 |
For each service file, change weekly to daily and set rotate to
3:
logrotate.conf. This allows you to customize retention periods for different
services. For example, you might want to keep NGINX logs longer than UFW firewall logs.
Test your log rotation configuration without actually rotating files:
-d flag runs in debug mode, showing what would happen without making actual changes.
Edit the default NGINX configuration to improve security and performance:
return 444; to deny direct IP address accessreturn 444; directive closes the connection
without sending a response when someone tries to access your server directly via IP address. This helps
prevent reconnaissance attacks and reduces unwanted traffic.
| Component | Status | Key Features |
|---|---|---|
| phpMyAdmin | โ Configured | 4-layer security, random URL, IP whitelisting |
| Log Rotation | โ Configured | Daily rotation, 7-day retention, compression enabled |
| NGINX Default | โ Optimized | Clean config, IP access blocked |
With phpMyAdmin secured and log rotation configured, your server is ready to host additional sites. The next section will cover hosting multiple sites using domain names and subdomains on your NGINX server.