Apache and Nginx are two of the most popular web servers used on Linux systems. Apache offers flexibility and easy configuration, while Nginx provides faster performance and efficient resource usage.
This guide explains how to switch between Apache and Nginx on a Linux server using simple command-line steps.
Table of Contents:
Introduction
When handling a Linux hosting server, you may need to switch between Apache and Nginx, two of the most popular open-source web servers.
- Apache is known for its flexibility, widespread compatibility, and easy integration with cPanel-based environments.
- Nginx is valued for its lightweight architecture and high performance under heavy traffic.
Switching between them can help improve your website’s speed, resource efficiency, or compatibility with specific applications.
Check Which Web Server Is Currently Running
First, check which web server is currently active.
- Use the following command:
sudo systemctl status apache2
or
sudo systemctl status nginx
- If one of them shows “active (running)”, that’s your current web server.
Stop and Disable the Current Web Server
To switch, you must first stop and disable the currently running one.
- For Apache:
sudo systemctl stop apache2 sudo systemctl disable apache2
- For Nginx:
sudo systemctl stop nginx sudo systemctl disable nginx
Install the Alternative Web Server
- To Install Nginx (if switching from Apache):
sudo apt install nginx -y
- To Install Apache (if switching from Nginx):
sudo apt install apache2 -y
Enable and Start the New Web Server
Once installed, start and enable the service:
- For Nginx:
sudo systemctl enable nginx sudo systemctl start nginx
- For Apache:
sudo systemctl enable apache2 sudo systemctl start apache2
Verify the Active Web Server
- Now, verify which web server is running after the switch, using the command below:
sudo systemctl status nginx or sudo systemctl status apache2
- You can also confirm by opening your server’s IP in a browser.
Conclusion
This way, switching between Apache and Nginx allows administrators to optimise server performance according to their website’s needs, using Apache for robust .htaccess-based configuration and compatibility, and Nginx for lightweight, high-speed static content delivery.
Want better control over server sessions? Learn How to create/set active session in Plesk