-
Notifications
You must be signed in to change notification settings - Fork 44
/
vhost.sh
executable file
·113 lines (100 loc) · 3.47 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/bin/bash
# Check if user is root
[ $(id -u) != "0" ] && echo "Error: You must be root to run this script, please use root to create vhost" && exit 1
echo "#######################################################################"
echo "# LNMP for CentOS/RadHat 5/6 #"
echo "# For more information please visit http://blog.linuxeye.com/82.html #"
echo "#######################################################################"
echo ''
while :
do
read -p "Please input domain(example: www.linuxeye.com linuxeye.com):" domain
if [ -z "`echo $domain | grep '.*\..*'`" ]; then
echo -e "\033[31minput error\033[0m"
else
break
fi
done
if [ ! -f "/usr/local/apache/conf/vhost/$domain.conf" ]; then
echo "################################"
echo "domain=$domain"
echo "################################"
else
echo "################################"
echo "$domain is exist!"
echo "################################"
exit 1
fi
read -p "Do you want to add more domain name? (y/n)" add_more_domainame
if [ "$add_more_domainame" == 'y' ]; then
while :
do
read -p "Type domainname,example(blog.linuxeye.com bbs.linuxeye.com):" moredomain
if [ -z "`echo $moredomain | grep '.*\..*'`" ]; then
echo -e "\033[31minput error\033[0m"
else
echo "################################"
echo domain list="$moredomain"
echo "################################"
moredomainame=" $moredomain"
break
fi
done
sa=ServerAlias$moredomainame
fi
echo "Please input the directory for the domain:$domain :"
read -p "(Default directory: /home/wwwroot/$domain):" vhostdir
if [ -z "$vhostdir" ]; then
vhostdir="/home/wwwroot/$domain"
fi
echo "################################"
echo Virtual Host Directory="$vhostdir"
echo "################################"
echo "################################"
read -p "Allow access_log? (y/n)" access_log
echo "################################"
if [ "$access_log" == 'n' ]; then
al='CustomLog "/dev/null" common'
else
al=CustomLog \"/home/wwwlogs/${domain}-access.log common\"
echo "################################"
echo You access log file="/home/wwwlogs/${domain}-access.log"
echo "################################"
fi
[ ! -d /usr/local/apache/conf/vhost ] && mkdir /usr/local/apache/conf/vhost
echo "Create Virtul Host directory......"
mkdir -p $vhostdir
echo "set permissions of Virtual Host directory......"
chown -R www.www $vhostdir
cat >/usr/local/apache/conf/vhost/$domain.conf<<EOF
<VirtualHost *:80>
ServerAdmin webmaster@$domain
DocumentRoot "$vhostdir"
ServerName $domain
$sa
ErrorLog "/home/wwwlogs/${domain}-error.log"
$al
<Directory "$vhostdir">
SetOutputFilter DEFLATE
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
DirectoryIndex index.html index.php
</Directory>
</VirtualHost>
EOF
echo "Test Apache configure file......"
/usr/local/apache/bin/apachectl -t
echo ""
echo "Restart Apache......"
/sbin/service httpd restart
echo "#######################################################################"
echo "# LNMP for CentOS/RadHat 5/6 #"
echo "# For more information please visit http://blog.linuxeye.com/82.html #"
echo "#######################################################################"
echo ''
echo -e "`printf "%-40s" "Your domain:"`\033[32m$domain\033[0m"
echo -e "`printf "%-40s" "Directory of $domain:"`\033[32m$vhostdir\033[0m"
echo ''
echo "#######################################################################"