-
Notifications
You must be signed in to change notification settings - Fork 5
/
installer.sh
253 lines (150 loc) · 5.04 KB
/
installer.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
247
248
249
250
251
252
253
#!/bin/bash -e
#Maintainer: Suraj Nair
#
#Check if we have privileges
#
if [ $(id -u) -ne 0 ]; then
echo "Run this script as a Root user only" >&2
exit 1
fi
#
# Getting IP from the system
#
IP=$(ip route get 8.8.8.8 | awk 'NR==1 {print $NF}')
#
#Check Error at any place and exit
#
checkerror() {
RESULT=$1
if [ $RESULT != 0 ];then
echo "Errors occured while installing, Check $LOGFILE"
exit 127
fi
}
#
# Fetching required vaiables to proceed
#
MYSQLPASSWORD=
while [[ $MYSQLPASSWORD = "" ]]; do
read -p "Please insert the new MySQL Password for root: " MYSQLPASSWORD
done
checkerror $?
WPDBNAME=
while [[ $WPDBNAME = "" ]]; do
read -p "Enter Wordpress Database name: " WPDBNAME
done
checkerror $?
WPUSER=
while [[ $WPUSER = "" ]]; do
read -p "Enter Wordpress Mysql user : " WPUSER
done
checkerror $?
WPPWD=
while [[ $WPPWD = "" ]]; do
read -p "Enter Wordpress Mysql password for above user: " WPPWD
done
checkerror $?
LOGFILE=/root/installlog.txt
echo "Updating repo information...\n"
apt-get update >> $LOGFILE
#
#Installing Apache2 package
#
echo "Installing Apache package now...\n"
apt-get -y install apache2 >> $LOGFILE 2>&1
checkerror $?
#
#Installing MySQL 5.7 which is available in default repo for Ubuntu 16.06
#
echo "Installing MySQL 5.7 now...\n"
echo "mysql-server-5.7 mysql-server/root_password password root" | sudo debconf-set-selections
echo "mysql-server-5.7 mysql-server/root_password_again password root" | sudo debconf-set-selections
apt-get -y install mysql-server-5.7 mysql-client >> $LOGFILE 2>&1
mysql -u root -proot -e "use mysql; UPDATE user SET authentication_string=PASSWORD('$MYSQLPASSWORD') WHERE User='root'; flush privileges;" >> $LOGFILE 2>&1
checkerror $?
#
#Installing PHP 7.0
#
echo "Installing PHP 7.0 now...\n"
apt-get install php7.0-mysql php7.0-curl php7.0-json php7.0-cgi php7.0 libapache2-mod-php7.0 -y >> $LOGFILE 2>&1
checkerror $?
#
#Creating Wordpress DB User and passwords with privileges.
#
echo "Creating Wordpress DB Users and grating privileges with already collected information...\n"
mysql -u root -p$MYSQLPASSWORD <<MYSQL_SCRIPT
CREATE DATABASE $WPDBNAME DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
GRANT ALL ON $WPDBNAME.* TO '$WPUSER'@'localhost' IDENTIFIED BY '$WPPWD';
FLUSH PRIVILEGES;
MYSQL_SCRIPT
checkerror $?
#
# Installing additional PHP plugins required by Wordpress as a default set
#
echo "Installing additional PHP plugins as a default set which might be required by Wordpress... \n
NOTE: Each WordPress plugin has its own set of requirements. Some may require additional PHP packages to be installed. Check your plugin documentation to discover its PHP requirements \n"
apt-get install php-curl php-gd php-mbstring php-mcrypt php-xml php-xmlrpc -y >> $LOGFILE 2>&1
checkerror $?
#
# Restarting Apache to take new additions into effect
#
echo "Restarting Apache to get the new additions into effect..\n"
systemctl restart apache2
checkerror $?
#
# Enabling mod_rewrite and .htaccess overwrites in Apache2
#
echo "Enabling mod_rewrite and .htaccess overwrites in Apache2...\n"
cat >> /etc/apache2/apache2.conf <<EOF
<Directory /var/www/html/>
AllowOverride All
</Directory>
EOF
a2enmod rewrite >> $LOGFILE 2>&1
checkerror $?
systemctl restart apache2 >> $LOGFILE 2>&1
checkerror $?
#
# Downloading latest Wordpress tarall and extraction
#
if [ ! -d /tmp ];then
mkdir /tmp
fi
cd /tmp
echo "Dowloading latest wordpress to tmp directory \n"
curl -O https://wordpress.org/latest.tar.gz >> $LOGFILE 2>&1
checkerror $?
tar xzvf /tmp/latest.tar.gz >> $LOGFILE 2>&1
checkerror $?
touch /tmp/wordpress/.htaccess
chmod 660 /tmp/wordpress/.htaccess
cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php
mkdir /tmp/wordpress/wp-content/upgrade
cp -a /tmp/wordpress/. /var/www/html
cd - >> $LOGFILE 2>&1
rm -f /var/www/html/index.html
echo "Setting reasonable file and directory permissions..\n"
chown -R www-data:www-data /var/www/html
find /var/www/html -type d -exec chmod g+s {} \;
chmod g+w /var/www/html/wp-content
chmod -R g+w /var/www/html/wp-content/themes
chmod -R g+w /var/www/html/wp-content/plugins
#
# Writing Wordpress config file with proper config data
#
echo "Writing Wordpress config file with proper config data...\n"
sed -i "s/database_name_here/$WPDBNAME/" /var/www/html/wp-config.php
sed -i "s/username_here/$WPUSER/" /var/www/html/wp-config.php
sed -i "s/password_here/$WPPWD/" /var/www/html/wp-config.php
echo "----------------------------------------------
Wordpress Installation has been completed successfully
Log file is at $LOGFILE
You may need to add the ServerName directive as required in the sites-enabled and sites-available conf files with DNS working properly for that servername.
Please browse to http://$IP to complete the installation through web interface
The information you'll need are as follows:
1) Wordpress Database Name: $WPDBNAME
2) Wordpress Database User: $WPUSER
3) Wordpress Database User Password: $WPPWD
Keep this handy with you............
Thank you!!
--------------------------------------------\n "