-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_virtual_host.sh
executable file
·36 lines (27 loc) · 1.08 KB
/
create_virtual_host.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
#!/bin/bash
# Apache
###########################################################
function apache_virtualhost {
# Configures a VirtualHost
# $1 - required - the hostname of the virtualhost to create
if [ ! -n "$1" ]; then
echo "apache_virtualhost() requires the hostname as the first argument"
return 1;
fi
if [ -e "/etc/apache2/sites-available/$1" ]; then
echo /etc/apache2/sites-available/$1 already exists
return;
fi
mkdir -p /srv/www/$1/public_html /srv/www/$1/logs
chown -fR root:www-data /srv/www/$1
echo "<VirtualHost *:80>" > /etc/apache2/sites-available/$1
echo " ServerName $1" >> /etc/apache2/sites-available/$1
echo " ServerAlias www.$1" >> /etc/apache2/sites-available/$1
echo " DocumentRoot /srv/www/$1/public_html/" >> /etc/apache2/sites-available/$1
echo " ErrorLog /srv/www/$1/logs/error.log" >> /etc/apache2/sites-available/$1
echo " CustomLog /srv/www/$1/logs/access.log combined" >> /etc/apache2/sites-available/$1
echo "</VirtualHost>" >> /etc/apache2/sites-available/$1
a2ensite $1
touch /tmp/restart-apache2
}
apache_virtualhost $1