Skip to content

Instantly share code, notes, and snippets.

@fjarrett
Last active June 7, 2021 09:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fjarrett/c5c17e9b93190313b200 to your computer and use it in GitHub Desktop.
Save fjarrett/c5c17e9b93190313b200 to your computer and use it in GitHub Desktop.
Remove a virtual host from Apache
#!/bin/bash
echo "Enter the domain of the site you want to remove:"
read DOMAIN
if [ ! -d /var/www/$DOMAIN ]; then
echo -e "\x1b[1;31mError:\e[0m $DOMAIN does not exist!"
exit 1
fi
sudo a2dissite -q $DOMAIN.conf
echo "Removing hosts..."
sudo grep -v "$DOMAIN" /etc/hosts > /tmp/hosts ; sudo mv /tmp/hosts /etc/hosts
echo "Removing config..."
sudo rm /etc/apache2/sites-available/$DOMAIN.conf
echo "Removing directories..."
sudo rm -R /var/www/$DOMAIN
echo "Reloading Apache..."
sudo service apache2 force-reload
echo -e "\x1b[1;32mSuccess:\e[0m $DOMAIN removed!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment