Uninstall and remove Apache2 on Ubuntu or Debian
Here is how you remove Apache2 cleanly on Ubuntu and Debian.
The first step is to stop any running instance of Apache2, because Apache2 will not be properly removed while it is running.
Then uninstall Apache2 and its dependent packages. Use purge option instead of remove with apt-get command. The former option will try to remove dependent packages, as well as any configuration files created by them. In addition, use autoremove option as well, to remove any other dependencies that were installed with Apache2, but are no longer used by any other package.
$ sudo apt-get autoremove
Finally, check if there is any configuration files or manual pages belonging to Apache2, which are still not removed.
In this example, /etc/apache2 directory still exists. Since this directory (as well as any configuration files in it) is no longer necessary, go ahead and remove it manually.