As you all know the NGINX and Apache servers, both use port 80 to access the root & to enhance security by preventing unauthorized services on critical points. Due to this, the entire files and database were mixed in between NGINX and Apache servers so I made up my mind to take a clear cut from the NGINX server by uninstalling it.
Therefore, in this blog post, we will walk you through the complete guide on uninstalling NGINX Server. Here’s you go!
Pre-Requisites to Uninstall NGINX Server
Before having a direct dive into the uninstalling procedure of the NGINX Server here we have to figure out all the prerequisites list. So, prior to jumping on the uninstalling concept let’s get to know what all you need to have:-
- Linux Terminal
- Ubuntu Server
A Stepwise Guide on Uninstalling NGINX Server and Enable Apache | Let’s Reveal
Preliminary to move towards uninstalling the NGINX Server, you must have to take up a backup of your website’s files to be safe for the forthcoming period.
Once, you have taken the backup of your essential data then execute the following steps to Uninstall NGINX Server without any stumbling blocks —
Read Also: TCP/IP NetBIOS Helper On or Off | What’s the Impact on Network Performance?
Step 1: Terminate Your NGINX Services
Before proceeding with the NGINX uninstalling procedure, you have to stop the services of your NGINX Server to ensure it’s not running.
To do this, you have to open up the Terminal window first and Stop the NGINX service by running the command:-
sudo systemctl stop nginx
Step 2: Deactivate the NGINX Services
Next to stopping the NGINX services, you have to deactivate them as well. To prevent your NGINX services from starting automatically at their boot time, run the below command:-
sudo systemctl disable nginx
Step 3: Uninstall Your NGINX Server
To uninstall your NGINX package from your system, you need to follow the below-mentioned command:-
sudo apt-get remove nginx nginx-common nginx-core
Step 4: Remove Your Entire Configuring Files
Here, you have to use this command to remove any leftover configuration files and directories:-
sudo apt-get purge nginx nginx-common nginx-core
Step 5: Clean-Up Remaining Dependencies
To Clean up any remaining dependencies and cached packages, follow the below command:-
sudo apt-get autoremove
sudo apt-get autoclean
Step 6: Verify Your Removal
To check out the status of your NGINX Server removal or to confirm it is no longer installed in your system, follow the below command:-
nginx -v
This command will return a “command not found” message if NGINX has been successfully uninstalled. So, be sure whether it has been uninstalled or not.
Step 7: Remove User Data (Optional)
If you want to remove the user data or log the related NGINX files then you can delete those directories manually using the below command:-
sudo rm -rf /etc/nginx
sudo rm -rf /var/log/nginx
sudo rm -rf /var/www/html
Once, you have uninstalled your NGINX Server completely and successfully then you may be required to switch on another one to work fluently in the near future. Therefore, we will let you know how you can enable Apache Server after uninstalling the NGINX one.
Need to Re-install the NGINX Server? | Let’s Do it
If you have uninstalled the NGINX Server and later you have realized that you are now in need to use it again so here we have revealed a way to re-install the NGINX Server.
Here’s You Go!
Step 1: Update the Package List
Before you move toward installing any package, it’s a good practice to update the package list to ensure that you have the latest information on the available packages.
sudo apt update
Step 2: Install NGINX
Next, the step is to install the NGINX server so use the following command:-
sudo apt install nginx
Step 3: Start NGINX Service
Once you have installed the NGINX Server then you have to start it’s service using the below command:-
sudo systemctl start nginx
Step 4: Enable NGINX to Start on the Boot
To ensure NGINX starts automatically when the system boots you have to enable it by using the further down command:-
sudo systemctl enable nginx
Step 5: Verify NGINX Installation
Here, you have to confirm that NGINX has been installed and is running as well along with checking its status with the mentioned command:-
sudo systemctl status nginx
You can also confirm it by opening a web browser & navigating to your server’s IP address and getting the default NGINX welcome page there.
Step 6: Configure Firewall (Optional)
If you have a firewall running on your system then, you may need to allow the HTTP and HTTPS traffic using the following commands:-
sudo ufw allow 'Nginx HTTP'
sudo ufw allow 'Nginx HTTPS'
Step 7: Basic Configuration (Optional)
As you can see this one is a basic step to make some primary configurations to your NGINX setup. So, use the main configuration file which is located at /etc/nginx/nginx.conf
You, need to open it up by using your preferred text editor, for example:
sudo nano /etc/nginx/nginx.conf
Once, you have made the changes, then you have to restart the NGINX server by applying the below-mentioned command:-
sudo systemctl restart nginx
Step 8: Test NGINX Configuration
Before proceeding with NGINX restarting and after completing the essential changes in the configuration, it’s a good idea to test the configuration file for syntax errors. For this, use the right below command:-
sudo nginx -t
Step 9: Restart NGINX
Finally, here you can restart your NGINX Server to apply any new configurations using the further down command:-
sudo systemctl restart nginx
Using the mentioned path, you can re-install your NGINX server successfully and have more experience with NGINX services.
Authorize Apache Server | Enable Apache One After Removing the NGINX Server
Let’s proceed with the following steps to enable the Apache Server on your system —-
Step 1: Install Apache Server
To Enable or install the Apache Server, first you need to update the package list for which you have to follow the below command :-
sudo apt-get update
Once you have updated the package, you have to install the Apache server for you have to run the below command:-
sudo apt-get install apache2
Step 2: Enable and Start Apache Service
As you have enabled the services of the Apache Server then you need to start them by following the below command:-
sudo systemctl enable apache2
As you have enabled the services of the Apache Server then you need to start tehem by flowing the below command:-
sudo systemctl start apache2
Step 3: Verify Apache Installation
To verify the Apache Server Installation, first, you have to check the status of the Apache Server using the below command:-
sudo systemctl status apache2
Here, you have to be sure that the output of the Apache Server indicates its active (running) Status.
Once you have checked the status and confirmed it’s running successfully then you need to test it once. To do this, you have to open up a web browser and go to http://localhost or http://your_server_ip.
Make sure that you see the default Apache welcome page on the site.
Step 4: Configure Firewall (If applicable)
If it is possible for you then you should allow your Apache Server flow through the Firewall using the mentioned command:-
sudo ufw allow 'apache'
In case, there isn’t any Firewall ability in your system, then this command to proceed in your Apache Installing configuration:-
sudo ufw enable
Step 5: Optional – Additional Apache Configuration
Typically this one is an optional step in installing the Apache Server but following it, you can get more security and flexibility in your project running procedure. So, here you have to edit the Apache configuration files using the following command:-
- Main configuration file:
/etc/apache2/apache2.conf
- Virtual Hosts configuration:
/etc/apache2/sites-available/000-default.conf
Once, you have completed the additional configuration process then you need to restart it to Apply Changes. For this use this command:-
sudo systemctl restart apache2
Step 6: Finally, Confirm Apache is Running
This is the final step of Apache installation where you need to make sure that your Apache Server is running perfectly without any difficulty. For this, use the following command:-
sudo systemctl status apache2
Additionally, make sure that your Apache Server is showing the active and running status.
Let’s Sum Up!
In this blog post, you will get complete and stepwise guidance uninstalling the NGINX server, re-install NGINX, and enabling the Apache Server from rise to finale. In addition to this, you will get guidance on prerequisites for uninstalling the NGINX Server. Therefore, let’s jump into the article without any further ado.
Related Post
How to Install PHP 8.3 and MySQL 8.0 on Ubuntu 22.04 in Microsoft Azure using NGINX/Apache Server?