-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvHost.sh
executable file
·42 lines (29 loc) · 999 Bytes
/
vHost.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
#!/bin/bash
read -p 'Enter Virtual Host : ' virtualHost
vhostFileEnabledSites=/etc/apache2/sites-enabled/$virtualHost.conf
if [ -f "$vhostFileEnabledSites" ]; then
echo "$vhostFileEnabledSites Host Already Exists"
exit 1
fi
read -p 'Enter Virtual Directory : ' virtualHostDirectory
if [ ! -d "$virtualHostDirectory" ]; then
echo "$virtualHostDirectory Directory Not Exists"
exit 1
fi
echo "127.0.0.1 $virtualHost" | sudo tee -a /etc/hosts
echo "<VirtualHost *:80>
DocumentRoot \"$virtualHostDirectory\"
ServerName www.$virtualHost
ServerAlias $virtualHost
<Directory \"$virtualHostDirectory\">
Options FollowSymLinks
AllowOverride All
Options -Indexes
</Directory>
</VirtualHost>
" | sudo tee -a /etc/apache2/sites-available/$virtualHost.conf
sudo a2ensite $virtualHost.conf
sudo service apache2 restart
echo " | ----------------------------- | "
echo " | --- Virtual Host Is Ready --- | "
echo " | ----------------------------- | "