The Apache web server, often referred to as Apache HTTP Server, is one of the most widely used web servers in the world. It’s known for its stability, performance, and reliability. However, there are instances where you might need to uninstall Apache from your system. Whether you’re switching to a different web server or no longer require Apache, this step-by-step guide will walk you through the process of uninstalling Apache from various operating systems.
Why Uninstall Apache Web Server ?
There can be several reasons for uninstalling Apache from your server or local machine:
- Transition to a different web server: You may have decided to switch to a different web server, such as Nginx or LiteSpeed, to better suit your needs.
- Security concerns: If you’re no longer using Apache and want to minimize potential security vulnerabilities, it’s a good idea to remove it from your system.
- Freeing up system resources: Uninstalling Apache can free up system resources, particularly if you have limited server resources or are running multiple web servers.
Uninstalling Apache on Ubuntu/Debian
To remote/uninstall Apache Web Server from Ubuntu is simple and straightforward way. For systems using the APT package manager, Apache can be uninstalled using the following commands:
1. Stop apache2 service
2. Uninstall Apache2 and its dependent packages
3. Use autoremove option to get rid of other dependencies
4. Check whether there are any configuration files that have not been removed
Step 1: Stop apache2 service
At this step, we will stop Apache web server by submitting command line :
$ sudo systemctl stop apache2 $ sudo systemctl status apache2
We will find Apache2 stoped as shown below :
ramansah@bckinfo:~$ sudo systemctl status apache2 × apache2.service - The Apache HTTP Server Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled) Active: failed (Result: exit-code) since Mon 2023-10-30 12:51:09 WIB; 1h 12min ago Docs: https://httpd.apache.org/docs/2.4/ Process: 4198 ExecStart=/usr/sbin/apachectl start (code=exited, status=1/FAILURE) CPU: 46ms Okt 30 12:51:09 bckinfo systemd[1]: Starting The Apache HTTP Server... Okt 30 12:51:09 bckinfo apachectl[4203]: (98)Address already in use: AH00072: make_sock: could not > Okt 30 12:51:09 bckinfo apachectl[4203]: (98)Address already in use: AH00072: make_sock: could not > Okt 30 12:51:09 bckinfo apachectl[4203]: no listening sockets available, shutting down Okt 30 12:51:09 bckinfo apachectl[4203]: AH00015: Unable to open logs Okt 30 12:51:09 bckinfo apachectl[4198]: Action 'start' failed. Okt 30 12:51:09 bckinfo apachectl[4198]: The Apache error log may have more information. Okt 30 12:51:09 bckinfo systemd[1]: apache2.service: Control process exited, code=exited, status=1/> Okt 30 12:51:09 bckinfo systemd[1]: apache2.service: Failed with result 'exit-code'. Okt 30 12:51:09 bckinfo systemd[1]: Failed to start The Apache HTTP Server.
Step 2 : Uninstall Apache2 and its dependent packages
At this step, we will uninstall Apache and its dependent pacakges. For this purpose we will submit following comands :
$ sudo apt-get purge apache2 $ sudo apt-get purge apache2-utils $ sudo apt-get purge apache2.2-bin
Output :
ramansah@bckinfo:~$ sudo apt-get purge apache2 Reading package lists... Done Building dependency tree... Done Reading state information... Done The following packages were automatically installed and are no longer required: apache2-data apache2-utils Use 'sudo apt autoremove' to remove them. The following packages will be REMOVED: apache2* 0 upgraded, 0 newly installed, 1 to remove and 185 not upgraded. After this operation, 546 kB disk space will be freed. Do you want to continue? [Y/n] Y (Reading database ... 285216 files and directories currently installed.) Removing apache2 (2.4.52-1ubuntu4.6) ... Processing triggers for man-db (2.10.2-1) ... Processing triggers for ufw (0.36.1-4build1) ... (Reading database ... 285161 files and directories currently installed.) Purging configuration files for apache2 (2.4.52-1ubuntu4.6) ... Processing triggers for ufw (0.36.1-4build1) ... ramansah@bckinfo:~$ sudo apt-get purge apache2-utils Reading package lists... Done Building dependency tree... Done Reading state information... Done The following package was automatically installed and is no longer required: apache2-data Use 'sudo apt autoremove' to remove it. The following packages will be REMOVED: apache2-utils* 0 upgraded, 0 newly installed, 1 to remove and 185 not upgraded. After this operation, 406 kB disk space will be freed. Do you want to continue? [Y/n] Y (Reading database ... 285002 files and directories currently installed.) Removing apache2-utils (2.4.52-1ubuntu4.6) ... Processing triggers for man-db (2.10.2-1) ... ramansah@bckinfo:~$ sudo apt-get purge apache2.2-bin Reading package lists... Done Building dependency tree... Done Reading state information... Done Package 'apache2.2-bin' is not installed, so not removed The following package was automatically installed and is no longer required: apache2-data Use 'sudo apt autoremove' to remove it. 0 upgraded, 0 newly installed, 0 to remove and 185 not upgraded.
Step 3: Use Autoremove option to get rid of other dependencies
sudo apt-get autoremove
Step 4 : Check If There are any Configuration Files that have not been removed
We will verify if there are no Apache web server configuration files remained. For this purpose we will submit following command line :
$ which apache2
Output :
ramansah@bckinfo:~$ which apache2 /usr/sbin/apache2 ramansah@bckinfo:~$ sudo rm -rf /etc/sbin/apache2
Conclusion
Uninstalling the Apache web server is a straightforward process, but the specific steps can vary based on your operating system. It’s important to remove Apache properly to avoid any leftover configuration files or security risks. After uninstalling Apache, consider whether you need an alternative web server or if your system requirements have changed. Whatever your reason for uninstalling Apache, following the appropriate steps will help you maintain a clean and secure server environment.