-
Notifications
You must be signed in to change notification settings - Fork 0
/
wordpress.sh
246 lines (193 loc) · 8.24 KB
/
wordpress.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#!/bin/bash
#####################################################
#Script to confiruge Server, WebServer and WordPress#
#####################################################
#Colors settings
BLUE='\033[0;34m'
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[0;33m'
NC='\033[0m' # No Color
#Welcome message
echo -e "Welcome to WordPress installation and configuration wizard!"
apt-get update
apt-get install -y locales
rm -rf /var/lib/apt/lists/*
localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8
export LANG=en_US.utf8
echo -e "Installing PhpMyAdmin MySQL web client..."
sleep 5
service apache2 start
service mysql start
add-apt-repository "deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc) universe"
apt-get install -y php7.3-mbstring php7.3-mysqli phpmyadmin
#Checking packages
echo -e "${YELLOW}Checking packages...${NC}"
echo -e "List of required packeges: nano, zip, unzip, mc, htop, apache2 & php, mysql, php curl, phpmyadmin, wget, curl"
read -r -p "Do you want to check packeges? [y/N] " response
case $response in
[yY][eE][sS]|[yY])
NANO=$(dpkg-query -W -f='${Status}' nano 2>/dev/null | grep -c "ok installed")
if [ $(dpkg-query -W -f='${Status}' nano 2>/dev/null | grep -c "ok installed") -eq 0 ];
then
echo -e "${YELLOW}Installing nano${NC}"
apt-get install nano --yes;
elif [ $(dpkg-query -W -f='${Status}' nano 2>/dev/null | grep -c "ok installed") -eq 1 ];
then
echo -e "${GREEN}nano is installed!${NC}"
fi
ZIP=$(dpkg-query -W -f='${Status}' zip 2>/dev/null | grep -c "ok installed")
if [ $(dpkg-query -W -f='${Status}' zip 2>/dev/null | grep -c "ok installed") -eq 0 ];
then
echo -e "${YELLOW}Installing zip${NC}"
apt-get install zip --yes;
elif [ $(dpkg-query -W -f='${Status}' zip 2>/dev/null | grep -c "ok installed") -eq 1 ];
then
echo -e "${GREEN}zip is installed!${NC}"
fi
MC=$(dpkg-query -W -f='${Status}' mc 2>/dev/null | grep -c "ok installed")
if [ $(dpkg-query -W -f='${Status}' mc 2>/dev/null | grep -c "ok installed") -eq 0 ];
then
echo -e "${YELLOW}Installing mc${NC}"
apt-get install mc --yes;
elif [ $(dpkg-query -W -f='${Status}' mc 2>/dev/null | grep -c "ok installed") -eq 1 ];
then
echo -e "${GREEN}mc is installed!${NC}"
fi
HTOP=$(dpkg-query -W -f='${Status}' htop 2>/dev/null | grep -c "ok installed")
if [ $(dpkg-query -W -f='${Status}' htop 2>/dev/null | grep -c "ok installed") -eq 0 ];
then
echo -e "${YELLOW}Installing htop${NC}"
apt-get install htop --yes;
elif [ $(dpkg-query -W -f='${Status}' htop 2>/dev/null | grep -c "ok installed") -eq 1 ];
then
echo -e "${GREEN}htop is installed!${NC}"
fi
APACHE2=$(dpkg-query -W -f='${Status}' apache2 2>/dev/null | grep -c "ok installed")
if [ $(dpkg-query -W -f='${Status}' apache2 2>/dev/null | grep -c "ok installed") -eq 0 ];
then
echo -e "${YELLOW}Installing apache2${NC}"
apt-get install apache2 php5 --yes;
elif [ $(dpkg-query -W -f='${Status}' apache2 2>/dev/null | grep -c "ok installed") -eq 1 ];
then
echo -e "${GREEN}apache2 is installed!${NC}"
fi
MYSQL=$(dpkg-query -W -f='${Status}' mysql-server 2>/dev/null | grep -c "ok installed")
if [ $(dpkg-query -W -f='${Status}' mysql-server 2>/dev/null | grep -c "ok installed") -eq 0 ];
then
echo -e "${YELLOW}Installing mysql-server${NC}"
apt-get install mysql-server --yes;
elif [ $(dpkg-query -W -f='${Status}' mysql-server 2>/dev/null | grep -c "ok installed") -eq 1 ];
then
echo -e "${GREEN}mysql-server is installed!${NC}"
fi
PHP5CURL=$(dpkg-query -W -f='${Status}' php5-curl 2>/dev/null | grep -c "ok installed")
if [ $(dpkg-query -W -f='${Status}' php5-curl 2>/dev/null | grep -c "ok installed") -eq 0 ];
then
echo -e "${YELLOW}Installing php5-curl${NC}"
apt-get install php5-curl --yes;
elif [ $(dpkg-query -W -f='${Status}' php5-curl 2>/dev/null | grep -c "ok installed") -eq 1 ];
then
echo -e "${GREEN}php5-curl is installed!${NC}"
fi
PHPMYADMIN=$(dpkg-query -W -f='${Status}' phpmyadmin 2>/dev/null | grep -c "ok installed")
if [ $(dpkg-query -W -f='${Status}' phpmyadmin 2>/dev/null | grep -c "ok installed") -eq 0 ];
then
echo -e "${YELLOW}Installing phpmyadmin${NC}"
apt-get install phpmyadmin --yes;
elif [ $(dpkg-query -W -f='${Status}' phpmyadmin 2>/dev/null | grep -c "ok installed") -eq 1 ];
then
echo -e "${GREEN}phpmyadmin is installed!${NC}"
fi
WGET=$(dpkg-query -W -f='${Status}' wget 2>/dev/null | grep -c "ok installed")
if [ $(dpkg-query -W -f='${Status}' wget 2>/dev/null | grep -c "ok installed") -eq 0 ];
then
echo -e "${YELLOW}Installing wget${NC}"
apt-get install wget --yes;
elif [ $(dpkg-query -W -f='${Status}' wget 2>/dev/null | grep -c "ok installed") -eq 1 ];
then
echo -e "${GREEN}wget is installed!${NC}"
fi
CURL=$(dpkg-query -W -f='${Status}' curl 2>/dev/null | grep -c "ok installed")
if [ $(dpkg-query -W -f='${Status}' curl 2>/dev/null | grep -c "ok installed") -eq 0 ];
then
echo -e "${YELLOW}Installing curl${NC}"
apt-get install curl --yes;
elif [ $(dpkg-query -W -f='${Status}' curl 2>/dev/null | grep -c "ok installed") -eq 1 ];
then
echo -e "${GREEN}curl is installed!${NC}"
fi
;;
*)
echo -e "${RED}
Packeges check is ignored!
Please be aware, that apache2, mysql, phpmyadmin and other software may not be installed!
${NC}"
;;
esac
#downloading WordPress, unpacking, adding basic pack of plugins, creating .htaccess with optimal & secure configuration
echo -e "${YELLOW}On this step we going to download latest version of WordPress in EN language...${NC}"
read -r -p "Do you want to install WordPress? [y/N] " response
case $response in
[yY][eE][sS]|[yY])
wget https://wordpress.org/latest.zip -O /workspace/wp_eng.zip
echo -e "Unpacking WordPress into website home directory..."
sleep 5
unzip /workspace/wp_eng.zip -d /workspace/wp/
mv /workspace/wp/wordpress/* /workspace/wp/
rm -rf /workspace/wp/wordpress/
rm /workspace/wp_eng.zip
mkdir /workspace/wp/wp-content/uploads
chmod -R 777 /workspace/wp/wp-content/uploads
;;
*)
echo -e "${RED}WordPress and plugins were not downloaded & installed. You can do this manually or re run this script.${NC}"
;;
esac
echo -e "${GREEN}Creating user & database for WordPress, setting wp-config.php...${NC}"
echo -e "Please, set username for Wordpress database: "
read db_user
echo -e "Please, set password for Wordpress database user: "
read db_pass
echo -e "Logging in to MySQL (default password is empty, simply press Enter) "
mysql -u root -p <<EOF
CREATE USER '$db_user'@'localhost' IDENTIFIED BY '$db_pass';
CREATE DATABASE IF NOT EXISTS $db_user;
GRANT ALL PRIVILEGES ON $db_user.* TO '$db_user'@'localhost';
ALTER DATABASE $db_user CHARACTER SET utf8 COLLATE utf8_general_ci;
EOF
cat >/workspace/wp/wp-config.php <<EOL
<?php
define('DB_NAME', '$db_user');
define('DB_USER', '$db_user');
define('DB_PASSWORD', '$db_pass');
define('DB_HOST', 'localhost');
define('DB_CHARSET', 'utf8');
define('DB_COLLATE', '');
define('AUTH_KEY', '$db_user');
define('SECURE_AUTH_KEY', '$db_user');
define('LOGGED_IN_KEY', '$db_user');
define('NONCE_KEY', '$db_user');
define('AUTH_SALT', '$db_user');
define('SECURE_AUTH_SALT', '$db_user');
define('LOGGED_IN_SALT', '$db_user');
define('NONCE_SALT', '$db_user');
\$table_prefix = 'wp_';
define('WP_DEBUG', false);
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
require_once(ABSPATH . 'wp-settings.php');
EOL
echo -e "${GREEN}Database user, database and wp-config.php were succesfully created & configured!${NC}"
service apache2 restart
service mysql restart
echo -e "
"
sleep 1
echo -e "You can now connect to MySQL as root (no passwd) via https://...run-eu-central1.goorm.io/phpmyadmin "
echo -e "You can now connect to Wordpress and continue online installation via https://...run-eu-central1.goorm.io/wp"
echo "<html><head><meta http-equiv='refresh' content='0; URL=/wp' /></head><body><a href='/wp'>Go to Wordpress</a></body></html>" > ./index.html
echo "<html><head><meta http-equiv='refresh' content='0; URL=/wp' /></head><body><a href='/wp'>Go to Wordpress</a></body></html>" > ../index.html
sleep 3
echo -e "Installation & configuration succesfully finished.
Bye!"