-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvhost.sh
90 lines (77 loc) · 2.05 KB
/
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
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
90
#!/bin/bash
# Author: Vladyslav Piskunov <[email protected]>
clear
echo 'Welcome to Apache2 Virtual Host Creator!'
echo ''
echo 'Hosts will be created in:'
echo '/etc/apache2/sites-available'
echo '/etc/apache2/sites-enabled'
echo ''
echo ''
echo 'Please enter domain name:'
read domainName
if [ $domainName ]; then
echo " ### Set domain name to: $domainName"
else
echo ' ### ERROR: no Domain Name given! Exiting...'
echo ''
echo ''
exit 0
fi
echo ''
echo 'Please enter which IP to listen at:[*]'
read ipaddress
if [ $ipaddress ]; then
echo -e " ### Setting IP address to $ipaddress"
else
echo " ### Setting IP adress to '*' (all IPs, default)"
ipaddress='*'
fi
echo ''
echo 'Please enter which Port to listen at:[80]'
read port
if [ $port ]; then
echo -e " ### Setting port to $port"
else
echo " ### Setting port to 80 (default)"
port='80'
fi
echo ''
echo ''
echo 'Please enter host root directory name(without /var/www/):'
read dirName
if [ $dirName ]; then
echo ''
else
echo ' ### ERROR: no ROOT Directory Name given! Exiting...'
echo ''
echo ''
exit 0
fi
vhost="<VirtualHost $ipaddress:$port>
ServerName $domainName
ServerAlias www.$domainName
DocumentRoot '/var/www/$dirName'
<Directory />
Require all granted
Options -Indexes +FollowSymLinks +Includes +ExecCGI
IndexIgnore css js fonts images
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>"
if [ ! -e "/etc/apache2/sites-available/generated-$domainName.conf" ]; then
echo "$vhost" > /etc/apache2/sites-available/generated-$domainName.conf
else
echo ' ### ERROR: sites-available => file exists already!'
exit 0
fi
if [ ! -e "/etc/apache2/sites-enabled/generated-$domainName.conf" ]; then
ln -s ../sites-available/generated-$domainName.conf /etc/apache2/sites-enabled/generated-$domainName.conf
else
echo ' ### ERROR: sites-enabled => file exists already!'
exit 0
fi
echo 'Restarting apache... Please wait...'
service apache2 restart