-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathadd-apache-vhost.sh
executable file
·53 lines (40 loc) · 1.03 KB
/
add-apache-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
#!/bin/bash
###
echo -n "Short name? (e.g. /var/www/shortname) "
read SHORTNAME
if [ -z "$SHORTNAME" ];
then
echo "Short name required."
exit
fi
###
echo -n "Host? (e.g. www.example.com) "
read HOSTNAME
if [ -z "$HOSTNAME" ];
then
echo "Host required."
exit
fi
###
mkdir -p /var/www/$SHORTNAME
mkdir -p /var/www/$SHORTNAME/html
mkdir -p /var/www/$SHORTNAME/logs
cat > /etc/apache2/sites-available/${SHORTNAME}.conf << EOF
<VirtualHost *:80>
ServerName $HOSTNAME
ErrorLog /var/www/$SHORTNAME/logs/error.log
CustomLog /var/www/$SHORTNAME/logs/access.log combined
DocumentRoot /var/www/$SHORTNAME/html
<Directory /var/www/$SHORTNAME/html/>
Options FollowSymLinks ExecCGI
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
EOF
ln -s /etc/apache2/sites-available/${SHORTNAME}.conf /etc/apache2/sites-enabled/${SHORTNAME}.conf
service apache2 reload
chown -R www-data:www-data /var/www/$SHORTNAME
echo ""
echo "Use \"vim /etc/apache2/sites-enabled/${SHORTNAME}.conf\" to edit vhost"
echo ""