-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremovehost.sh
61 lines (52 loc) · 1.88 KB
/
removehost.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
# =========================================================================
# Local Apache Host Manager - Remove host from apache config
# =========================================================================
# Author: Shakil Ahmed
# Website: https://shakilahmeed.com
# Created: January 2025
# Description: Remove host, ssl config from local
# License: MIT
# =========================================================================
# Ensure script is run as root
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi
# Input domain
read -p "Enter the custom domain to remove (e.g., myproject.local): " domain
# 1. Remove domain from /etc/hosts
sed -i "/$domain/d" /etc/hosts
echo "Removed $domain from /etc/hosts."
# 2. Remove SSL certificates and directory
ssl_dir="/etc/ssl/$domain"
if [ -d "$ssl_dir" ]; then
rm -rf $ssl_dir
echo "Removed SSL certificates for $domain."
else
echo "SSL directory for $domain not found."
fi
# 3. Remove Apache site configuration
apache_conf="/etc/apache2/sites-available/$domain.conf"
if [ -f "$apache_conf" ]; then
# Disable site before removing configuration
a2dissite $domain.conf > /dev/null 2>&1
rm $apache_conf
echo "Removed Apache virtual host configuration for $domain."
else
echo "Apache virtual host configuration for $domain not found."
fi
# 4. Clean up SSL certificate from mkcert (if exists)
if command -v mkcert &> /dev/null; then
caroot=$(mkcert -CAROOT)
if [ -d "$caroot" ]; then
# Remove any domain-specific certificates if they exist
find "$caroot" -name "*$domain*" -delete 2>/dev/null
echo "Cleaned up mkcert certificates for $domain."
fi
fi
# 5. Restart Apache
systemctl restart apache2
# Final message
echo "Successfully removed all configurations for $domain."
echo "You may want to clear your browser's SSL cache and restart the browser."