If you’re using aaPanel to manage your web server, you’ve probably noticed that Nginx is often the default web server. While Nginx is powerful, some users prefer Apache due to its flexibility, extensive module support, and .htaccess file compatibility. This guide will provide a detailed walkthrough on installing Apache instead of Nginx in aaPanel.
This guide assumes basic knowledge of aaPanel, Linux, and command-line operations. With step-by-step instructions and practical examples, you’ll successfully transition to Apache while maintaining a stable and optimized web server.
Before transitioning, it’s essential to understand the differences between Apache and Nginx to ensure that Apache meets your project requirements.
Apache:
Nginx:
By choosing Apache, you prioritize flexibility and modularity, which might be better suited for your use case.
Before proceeding, check that the following prerequisites are met:
Updated System: Update the server to the latest stable version to avoid compatibility issues.
sudo apt update && sudo apt upgrade -y # For Debian/Ubuntu

sudo yum update -y # For CentOS
Always back up your existing configuration before making significant changes.
Backup Websites and Databases: Use aaPanel’s backup feature to back up your website files and databases completely.
Export Nginx Configurations: Export your current Nginx configurations for reference or rollback purposes.
cp /www/server/nginx/conf /www/server/nginx/conf.bak

Removing Nginx from aaPanel is necessary to install Apache without conflicts.
Stop Nginx:


Uninstall Nginx:

Verify Removal:
Confirm that no Nginx processes are running:
ps aux | grep nginx

If any processes persist, kill them manually:
sudo kill -9 <nginx_process_id>k

Now that Nginx is uninstalled, proceed with Apache installation.
Install Apache:


Check if Apache is running:

Configuration is crucial for optimal Apache performance.
Basic Configuration:
Open the Apache configuration file:
nano /www/server/apache/conf/httpd.conf

Adjust critical parameters, such as:
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
Update DNS Records: Make sure your DNS records point to the server’s IP for proper domain resolution.
Check Apache Status: Run the following command to confirm that Apache is active:
sudo systemctl status apache2 # Debian/Ubuntu

sudo systemctl status httpd # CentOS
Test Websites: Open your browser and visit your domain to verify the website loads correctly.
Analyse Logs: Check logs for any errors or warnings:
tail -f /var/log/apache2/error.log # Debian/Ubuntu

tail -f /var/log/httpd/error_log # CentOS
To maximize performance, adjust the following settings:
Adjust MPM Settings: Modify Multi-Processing Modules (MPM) settings in the configuration file:
nano /www/server/apache/conf/httpd.conf
Example:

Enable Compression: Add the following lines to enable Gzip compression:

Implement Caching: Configure caching for static content using mod_expires:
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 month"
</IfModule>
Secure Your Server:
Here are solutions to common issues you may face:
Apache Fails to Start:
Check if Nginx is still running:
ps aux | grep nginx
Kill the process or make sure it’s uninstalled.

500 Internal Server Error:
sudo chmod -R 755 /www/wwwroot

Domain Not Resolving:
sudo systemctl restart apache2

Slow Performance:
Transitioning from Nginx to Apache in aaPanel is easy when approached methodically. This guide has covered every step, from uninstalling Nginx to fine-tuning Apache for optimal performance. Following these instructions lets you enjoy Apache’s flexibility and compatibility while efficiently managing your server through aaPanel.
For further customization, leverage Apache’s extensive module library and aaPanel’s monitoring and security tools. Remember to update your server regularly and back up configurations to maintain a stable environment.

Vinayak Baranwal wrote this article. Use the provided link to connect with Vinayak on LinkedIn for more insightful content or collaboration opportunities.