-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_vhost.sh
executable file
·109 lines (100 loc) · 2.32 KB
/
create_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
#!/bin/bash
SERVERNAME=""
SERVERALIAS=""
HOMEDIR=""
USERNAME=""
USERPASS=""
DBUSER=""
DBPASS=""
DBNAME=""
while :
do
echo "Domain name ?"
read SERVERNAME
if [ ! -z ${SERVERNAME} ]
then
break
fi
done
echo "Domain Aliases ? (multiple alias on one ligne, separated by a simple space, none if empty"
read SERVERALIAS
while :
do
echo "Username FTP/SSH ?"
read USERNAME
if [ ! -z ${USERNAME} ]
then
break
fi
done
while :
do
echo "Password ?"
read USERPASS
if [ ! -z ${USERPASS} ]
then
break
fi
done
while :
do
echo "Home directory ? (document_root will be automatilly generated, at HOMEDIR/public_html)"
read HOMEDIR
if [ ! -z ${HOMEDIR} ]
then
DOCUMENTROOT=$(echo /home/${HOMEDIR}/public_html)
break
fi
done
while :
do
echo "Database ? <y/n>"
read IS_DB
if [ ${IS_DB} == "y" ]
then
echo "database name ?"
read DBNAME
echo "DB user ?"
read DBUSER
echo "DB user pass ?"
read DBPASS
if [ ! -z ${DBNAME} ] && [ ! -z ${DBUSER} ] && [ ! -z ${DBPASS} ]
then
break
fi
elif [ ${IS_DB} == "n" ]
then
break
fi
done
echo "creating user"
useradd -d /home/$HOMEDIR -s /bin/bash $USERNAME
mkdir -p $DOCUMENTROOT
chown -R $USERNAME: /home/$HOMEDIR
echo $USERNAME:$USERPASS | chpasswd
echo "creating PHP pool"
cp /etc/php/7.0/fpm/pool.d/TEMPLATE /etc/php/7.0/fpm/pool.d/${USERNAME}.conf
sed -i "s@USERNAME@${USERNAME}@g" /etc/php/7.0/fpm/pool.d/${USERNAME}.conf
echo "restarting FPM"
systemctl restart php7.0-fpm.service
echo "Creating website"
cp /etc/apache2/sites-available/TEMPLATE /etc/apache2/sites-available/${USERNAME}.conf
sed -i "s@SERVERNAME@${SERVERNAME}@g" /etc/apache2/sites-available/${USERNAME}.conf
if [ ! -z ${SERVERALIAS} ]
then
sed -i "s@SERVERALIAS@${SERVERALIAS}@g" /etc/apache2/sites-available/${USERNAME}.conf
else
sed -i "s@.*ServerAlias SERVERALIAS.*@@g" /etc/apache2/sites-available/${USERNAME}.conf
fi
sed -i "s@DOCUMENTROOT@${DOCUMENTROOT}@g" /etc/apache2/sites-available/${USERNAME}.conf
sed -i "s@USERNAME@${USERNAME}@g" /etc/apache2/sites-available/${USERNAME}.conf
a2ensite ${USERNAME}.conf
apachectl configtest
apache2ctl graceful
if [ ! -z ${DBNAME} ] && [ ! -z ${DBUSER} ] && [ ! -z ${DBPASS} ]
then
echo "Creating database"
mysql -e "CREATE DATABASE ${DBNAME}; GRANT ALL PRIVILEGES ON ${DBNAME}.* TO '${DBUSER}'@'localhost' IDENTIFIED BY '${DBPASS}';"
else
echo "No database"
fi