-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-new-virtual-host.sh
More file actions
executable file
·113 lines (79 loc) · 2.38 KB
/
Copy pathcreate-new-virtual-host.sh
File metadata and controls
executable file
·113 lines (79 loc) · 2.38 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
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
# author: Sergey Serov
# DESCRIPTION
#############
# Create new virtual host on local workstation.
# Create directories, configs etc and restart Apache.
# HELP
######
# $1 = virtual host name
# Example: forge
# CONFIG
########
# set -x
name=$1
web_root='/var/www'
path="$web_root/$name"
TASK_NAME="Creating new local virtual host '$name'"
# PROGRAM
#########
work-start "$TASK_NAME"
if [ $# -ne 1 -o -z "$1" ]
then
print-error "Must be 1 parameter - virtual host name."
print-info "Usage: ./create-new-virtual-host.sh forge"
print-warning "Exit..."
exit 1
elif [ -d $path ]
then
print-error "Directory for virtual host already exists!"
print-warning "Exit..."
exit 2
fi
run-command "sudo mkdir $path"
run-command "sudo mkdir -m=755 $path/logs"
run-command "sudo mkdir -m=755 $path/sessions"
run-command "sudo mkdir -m=755 $path/tmp"
run-command "sudo mkdir -m=755 $path/www"
run-command "sudo chown -v www-data:www-data $path/logs"
run-command "sudo chown -v www-data:www-data $path/sessions"
run-command "sudo chown -v www-data:www-data $path/tmp"
run-command "sudo chown -v sergey:sergey $path/www"
print-info "Create new Apache config - /etc/apache2/sites-available/$name.conf"
echo "<VirtualHost *:80>
DocumentRoot $path/www
ServerName $name
ServerAlias www.$name
ErrorLog $path/logs/apache_error.log
<Directory $path/www>
Options -Indexes
AllowOverride All
Require all granted
</Directory>
php_admin_value open_basedir $path/www:$path/tmp
php_admin_value doc_root $path/www
php_admin_value upload_tmp_dir $path/tmp
php_admin_value error_log $path/logs/php.log
php_admin_value session.save_path $path/sessions
</VirtualHost>" | sudo tee /etc/apache2/sites-available/$name.conf
print-command "echo \"127.0.0.1 $name www.$name\" | sudo tee --append /etc/hosts"
echo "127.0.0.1 $name www.$name" | sudo tee --append /etc/hosts
run-command "sudo a2ensite $name.conf"
run-command "sudo service apache2 restart"
work-end-summary "$TASK_NAME"
# TODO
######
# check that two arguments were passed here. + permissions!
# output table: all current virtual host + /etc/hosts
# + Apache available/enabled sites
# + du
# ?+ touch index.html ++ echo 'this is ' $host_name
# + curl -I this new host
# WAREHOUSE
###########
#!/bin/bash -i
# sudo mkdir -v -m=755 $path/logs
# fc -s logs=sessions
# fc -s sessions=tmp
# fc -s tmp=www
set +x