-
Notifications
You must be signed in to change notification settings - Fork 0
/
webSetup.sh
executable file
·118 lines (82 loc) · 3.39 KB
/
webSetup.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
114
115
116
117
118
#!/bin/bash
if [ "$#" -ne 1 ]
then
echo -ne "Illegal number of arguments: USAGE: path/to/script siteName"
exit 1
fi
siteName=$1
MYSQL=$(dpkg -l | grep mariadb-server)
NGINX=$(dpkg -l | grep nginx)
PHP=$(dpkg -l | grep php-fpm)
MYSQLPASS="wp123"
MYSQLDATABASE="wordpress"
SERVERNAMEORIP="example.com"
#you may need to enter a password for mysql-server
debconf-set-selections <<< "mysql-server mysql-server/root_password password ${MYSQLPASS}"
debconf-set-selections <<< "mysql-server mysql-server/root_password_again password ${MYSQLPASS}"
if [ -z "$MYSQL" ]
then
echo "Installing Mysql Server"
`apt-get install -y python3 mariadb-server mariadb-client`
/etc/init.d/mysql start
echo "Mysql Server has been installed and started"
fi
if [ -z "$NGINX" ]
then
echo "Installing NGINX Server"
`apt-get install -y nginx`
/etc/init.d/nginx start
echo "Installed NGINX Server and started"
fi
if [ -z "$PHP" ]
then
echo "Installing PHP Server"
`apt-get install -y php-fpm php-mysql`
echo "Installed PHP Server"
fi
#read -p "Please enter your site name: " siteName
echo "127.0.0.1 $siteName" >> /etc/hosts
nginxRoot="/usr/share/nginx/html/$siteName"
nginxVHerror="$siteName".error;
nginxVHaccess="$siteName".access;
nginxConf="server { \n
\n
listen 80;\n
root /usr/share/nginx/html/$siteName;\n
index index.php index.html index.htm;\n
server_name $siteName;\n
\n
access_log /var/log/nginx/$nginxVHaccess;\n
error_log /var/log/nginx/$nginxVHerror error;\n
# location / {\n
# try_files \$uri \$uri/ /index.php?q=\$uri&\$args;\n
#}\n
\n
location ~ \.php$ {\n
#try_files \$uri =404;\n
include snippets/fastcgi-php.conf;\n
fastcgi_pass unix:/run/php/php7.0-fpm.sock;\n
}
}\n"
sed -i "s/^;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/" /etc/php/7.0/fpm/php.ini
sed -i "s/^;listen.owner = www-data/listen.owner = www-data/" /etc/php/7.0/fpm/pool.d/www.conf
sed -i "s/^;listen.group = www-data/listen.group = www-data/" /etc/php/7.0/fpm/pool.d/www.conf
sed -i "s/^;listen.mode = 0660/listen.mode = 0660/" /etc/php/7.0/fpm/pool.d/www.conf
/etc/init.d/php7.0-fpm start
`touch /etc/nginx/sites-available/$siteName.conf && echo -e $nginxConf >> /etc/nginx/sites-available/$siteName.conf && ln -s /etc/nginx/sites-available/$siteName.conf /etc/nginx/sites-enabled/$siteName.conf`
`wget -O /tmp/wordpress.zip https://wordpress.org/latest.zip && unzip -q /tmp/wordpress.zip -d /tmp/ && mv /tmp/wordpress /usr/share/nginx/html/$siteName`
PASSWDDB="$(openssl rand -base64 12)"
mainDB="$siteName"_db
mainDB_user="$siteName"_user
mysql -uroot -p$MYSQLPASS -e "CREATE DATABASE \`$mainDB\`"
mysql -uroot -p$MYSQLPASS -e "CREATE USER \`$mainDB_user\`@localhost IDENTIFIED BY '$PASSWDDB'"
mysql -uroot -p$MYSQLPASS -e "GRANT ALL PRIVILEGES ON \`$mainDB\`.* TO \`$mainDB_user\`@localhost IDENTIFIED BY '$PASSWDDB'"
mysql -uroot -p$MYSQLPASS -e "FLUSH PRIVILEGES"
db_old="define('DB_NAME', 'database_name_here');"
user_old="define('DB_USER', 'username_here');"
passwd_old="define('DB_PASSWORD', 'password_here');"
db_new="define( 'DB_NAME', '"$mainDB"' );"
user_new="define( 'DB_USER', '"$mainDB_user"' );"
passwd_new="define( 'DB_PASSWORD', '"$PASSWDDB"' );"
`sed -i -e "s/$db_old/$db_new/" -e "s/$user_old/$user_new/" -e "s/$passwd_old/$passwd_new/" "$nginxRoot/wp-config-sample.php" && mv "$nginxRoot/wp-config-sample.php" "$nginxRoot/wp-config.php"`
`/usr/sbin/nginx -s reload`