A very simple and straightforward way that worked for me since 2015 to now, is as follows:
sudo service apache2 stop
sudo apt-get purge apache2* -y
sudo apt-get autoremove -y
sudo rm -rf /usr/sbin/apache2 /usr/lib/apache2 /usr/share/apache2 /usr/share/man/man8/apache*
whereis apache2
Explaination:
- sudo service apache2 stop
- Stop the service
- sudo apt-get purge apache2* -y
- Uninstall the service
- sudo apt-get autoremove -y
- Cleaning the apt (advance packaging tools)
- sudo rm -rf /usr/sbin/apache2 /usr/lib/apache2 /usr/share/apache2 /usr/share/man/man8/apache*
- Remove the folders that created for Apache2
- whereis apache2
- Find Apache2 folders, if the results is Apache2: , means no more Apache2 in your Ubuntu Server