-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvhost.sh
More file actions
executable file
·89 lines (76 loc) · 2.11 KB
/
vhost.sh
File metadata and controls
executable file
·89 lines (76 loc) · 2.11 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
SERVER_DOMAIN=$1
function createWWW () {
echo "creating directory /var/www/"$SERVER_DOMAIN"/public"
sudo mkdir /var/www/$SERVER_DOMAIN
sudo mkdir /var/www/$SERVER_DOMAIN/public
sudo chmod -R 777 /var/www/$SERVER_DOMAIN
echo "It Works" > /var/www/$SERVER_DOMAIN/public/index.html
}
function createConfig () {
echo "Adding Virtual Host" $SERVER_DOMAIN
sudo sh -c 'echo "<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName '${SERVER_DOMAIN}'
ServerAlias www.'${SERVER_DOMAIN}'
DocumentRoot /var/www/'${SERVER_DOMAIN}'/public
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>" > /etc/apache2/sites-available/'${SERVER_DOMAIN}'.conf'
}
function showUsage() {
echo "To create config and www directory: ./vhost.sh mydomain.com"
echo "To create config only: ./vhost.sh mydomain.com off"
exit
}
function restartApache() {
echo "Restarting Apache"
sudo service apache2 restart
exit
}
function addSite(){
a2ensite $SERVER_DOMAIN
}
#if there in only domain in arguements
if [[ $# == 1 ]]; then
createWWW
createConfig
addSite
restartApache
fi
#check second command line arguement
if [[ $# == 2 ]]; then
if [[ $2 == "off" ]]; then
createConfig
addSite
restartApache
fi
fi
showUsage