Software Development

How can I completely uninstall and remove the Apache2 web server from my Ubuntu system?

JE Asked by Jessica Thompson · 14-04-2024
0 upvotes 14,421 views 0 comments
The question

I've decided to switch my web server from Apache2 to Nginx on my Ubuntu machine, and I want to make sure the old installation is entirely gone. I tried a simple remove command, but I still see configuration folders and some service entries left behind. What is the proper sequence of commands to purge the packages, remove dependencies, and delete any leftover config files safely?

3 answers

0
SA
Answered on 17-04-2024

To completely remove Apache2, you should use the purge command instead of just remove. Start by stopping the service with sudo systemctl stop apache2. Then, execute sudo apt-get purge apache2 apache2-utils apache2-bin apache2-common. This command removes the packages along with their configuration files. Afterward, run sudo apt-get autoremove to delete any orphaned dependencies that were only needed by Apache. To be absolutely thorough, manually check for the /etc/apache2 directory; if it still exists, you can delete it with sudo rm -rf /etc/apache2. This process ensures a "clean slate" for your next web server installation and prevents port conflicts or leftover service fragments from causing issues later.

0
RO
Answered on 19-04-2024

If I use the purge command, will it also delete the website files I have stored in /var/www/html/, or does it only target the server's own configuration and binary files?

ST 21-04-2024

That is an excellent question, Robert. The apt purge command is designed to remove the software and its configuration files (usually in /etc/), but it typically leaves your data in /var/www/ untouched. However, as an SEO and DevOps best practice, you should always create a backup of your web directory before running any destructive commands. If you want those files gone too, you would need to manually run sudo rm -rf /var/www/html after you have verified the uninstallation.

0
JE
Answered on 23-04-2024

ou can verify if it's truly gone by running which apache2 or apache2 -v. If the system returns "command not found," the uninstallation was successful.

J 25-04-2024

I agree with Jennifer. Another quick check is to run sudo systemctl status apache2. If it shows "Unit apache2.service could not be found," you’ve successfully cleared the service from the system's init manager as well!

Share your thoughts

Your email address will not be published. Required fields are marked (*)

Professional Counselling Session

Still have questions?
Schedule a free counselling session

Our experts are ready to help you with any questions about courses, admissions, or career paths. Get personalized guidance from industry professionals.

Request a Call Back

Search Online

We Accept

We Accept

Follow Us

"PMI®", "PMBOK®", "PMP®", "CAPM®" and "PMI-ACP®" are registered marks of the Project Management Institute, Inc. | "CSM", "CST" are Registered Trade Marks of The Scrum Alliance, USA. | COBIT® is a trademark of ISACA® registered in the United States and other countries.

Book Free Session