-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvirtualhost.sh
45 lines (32 loc) · 896 Bytes
/
virtualhost.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
#!/bin/bash
hostsFile=/private/etc/hosts
apacheFile=/etc/apache2/extra/httpd-vhosts.conf
read -e -p "What's the domain? http://" domain;
echo "All right, now I need to know where to put the docroot."
read -e -p "What's the local path? " path;
# replace ~ with absolute path
user=`whoami`
path=`echo $path | sed -E "s/~/\/Users\/$user/g"`
# remove the path trailing slash
path=`echo $path | sed 's#/*$##'`
sudo -s <<EOF
function getvhost()
{
cat <<- _EOF_
<Directory "$path/$domain/">
Allow From All
AllowOverride All
Options Indexes FollowSymLinks MultiViews
</Directory>
<VirtualHost *:80>
ServerName "$domain"
DocumentRoot "$path/$domain"
</VirtualHost>
_EOF_
}
#add the domain the the hosts file
echo "127.0.0.1 $domain" >> $hostsFile
getvhost >> $apacheFile
apachectl restart;
EOF
echo "$domain has been created at $path/$domain ";