-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_web_lamp.sh
executable file
·379 lines (326 loc) · 10.2 KB
/
install_web_lamp.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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
#!/bin/bash
if [ "$EUID" -ne 0 ]
then
#echo "Please run as root"
dialog --infobox "Please run as root" 5 25
read await
clear
exit
fi
echo "ATTENTION! LAMP must be installed to run this script correctly! If you use immers.cloud preinstalled image - ignore this message."
echo "Install selections:"
echo "[0]: PHPMyAdmin
[1]: WordPress
[2]: Laravel 8
[3]: Yii2 Basic
[4]: Yii2 Advanced"
if [ -z ${id_mode+x} ];
then
echo -n "Which one are you want to setup?: [0-4] "
read id_mode
# exec 3>&1;
# id_mode=$(dialog --title "LAMP Installation menu" --clear --menu "Which tool you wanna install?" 21 40 40 \
# "0" "PHPMyAdmin"\
# "1" "Wordpress"\
# "2" "Laravel 8"\
# "3" "Yii2 Basic"\
# "4" "Yii2 Advanced"\
# 2>&1 1>&3)
# exitcode=$?;
# exec 3>&-;
# if [ "$exitcode" != 0 ]
# then
# echo "Have a good day! Script stopped."
# exit 0
# fi
fi
case $id_mode in
0) #LAMP_PMA
#!/bin/bash
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
if [ -z ${user_mysql_root+x} ];
then
echo -n "Enter new mysql username: "
read user_mysql_root
fi
if [ -z ${pwd_mysql_root+x} ];
then
echo -n "Enter new mysql user password: "
read pwd_mysql_root
fi
user_mysql_exists="$(mysql -sse "SELECT EXISTS(SELECT 1 FROM mysql.user WHERE user = '$user_mysql_root')")"
if [ "$user_mysql_exists" != 1 ];
then
mysql << EOF
CREATE USER '${user_mysql_root}'@'localhost' IDENTIFIED BY '${pwd_mysql_root}';
GRANT ALL PRIVILEGES ON *.* to '${user_mysql_root}'@'localhost';
FLUSH PRIVILEGES;
EOF
service mysql restart
else
echo "Alert!: User exists. Ignoring mysql request."
fi
curl https://files.phpmyadmin.net/phpMyAdmin/5.1.2/phpMyAdmin-5.1.2-all-languages.zip --output /tmp/pma.zip
unzip /tmp/pma.zip -d /tmp/
mkdir /var/www/phpmyadmin
mv -f /tmp/phpMyAdmin-5.1.2-all-languages/* /var/www/phpmyadmin/
touch /etc/apache2/sites-available/zpma.conf
cat << EOF > /etc/apache2/sites-available/zpma.conf
ServerName zpma
Alias /phpmyadmin "/var/www/phpmyadmin"
<Directory "/var/www/phpmyadmin">
DirectoryIndex index.php
AllowOverride All
Options FollowSymlinks
Require all granted
</Directory>
EOF
ln -s /etc/apache2/sites-available/zpma.conf /etc/apache2/sites-enabled/
systemctl restart apache2
;;
1) #LAMP_WP
#!/bin/bash
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
#mysql_secure_installation
if [ -z ${db_wp_name+x} ];
then
echo -n "Enter new Wordpress Database name: "
read db_wp_name
fi
if [ -z ${db_wp_username+x} ];
then
echo -n "Enter new Wordpress Database username: "
read db_wp_username
fi
db_wp_username=\'$db_wp_username\'
if [ -z ${db_wp_password+x} ]
then
echo -n "Enter new Wordpress Database password: "
read db_wp_password
fi
db_wp_password=\'$db_wp_password\'
db_wp_host='localhost'
user_mysql_exists="$(mysql -sse "SELECT EXISTS(SELECT 1 FROM mysql.user WHERE user = $db_wp_username)")"
if [ "$user_mysql_exists" != 1 ];
then
mysql << EOF
CREATE USER ${db_wp_username}@${db_wp_host} IDENTIFIED BY ${db_wp_password};
GRANT ALL PRIVILEGES ON ${db_wp_name}.* to ${db_wp_username}@$db_wp_host;
FLUSH PRIVILEGES;
EOF
else
echo "Alert!: User exists. Ignoring mysql request."
fi
mysql << EOF
CREATE DATABASE IF NOT EXISTS ${db_wp_name};
EOF
mkdir /etc/ssl
mkdir /etc/ssl/certs
echo -n "Input Self-Signed certificate data, please:"
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/apache-selfsigned.key -out /etc/ssl/certs/apache-selfsigned.crt -subj "/C=/ST=/L=/O=/CN="
openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048
touch /etc/apache2/sites-available/wordpress.conf
touch /etc/apache2/conf-available/ssl-params.conf
cat << EOF > /etc/apache2/sites-available/wordpress.conf
<VirtualHost *:80>
DocumentRoot /var/www/wordpress
<Directory /var/www/wordpress>
Options FollowSymLinks
AllowOverride Limit Options FileInfo
DirectoryIndex index.php
Require all granted
</Directory>
<Directory /var/www/wordpress/wp-content>
Options FollowSymLinks
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:443>
DocumentRoot /var/www/wordpress
SSLEngine on
SSLCertificateFile /etc/ssl/certs/apache-selfsigned.crt
SSLCertificateKeyFile /etc/ssl/private/apache-selfsigned.key
<Directory /var/www/wordpress>
Options FollowSymLinks
AllowOverride Limit Options FileInfo
DirectoryIndex index.php
Require all granted
</Directory>
<Directory /var/www/wordpress/wp-content>
Options FollowSymLinks
Require all granted
</Directory>
</VirtualHost>
EOF
cat << EOF > /etc/apache2/conf-available/ssl-params.conf
SSLCipherSuite EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH
SSLProtocol All -SSLv2 -SSLv3
SSLHonorCipherOrder On
Header always set Strict-Transport-Security "max-age=63072000; includeSubdomains"
Header always set X-Frame-Options DENY
Header always set X-Content-Type-Options nosniff
SSLCompression off
SSLSessionTickets Off
SSLUseStapling on
SSLStaplingCache "shmcb:logs/stapling-cache(150000)"
SSLOpenSSLConfCmd DHParameters "/etc/ssl/certs/dhparam.pem"
EOF
a2enmod rewrite
sudo a2dissite 000-default
a2enmod ssl
a2enmod headers
a2enconf ssl-params
a2ensite wordpress
systemctl restart apache2
wget -O /tmp/wordpress.tar.gz https://wordpress.org/latest.tar.gz
tar -xzvf /tmp/wordpress.tar.gz -C /var/www
chown -R www-data.www-data /var/www/wordpress
cat << EOF > /var/www/wordpress/wp-config.php
<?php
define( 'DB_NAME', '${db_wp_name}' );
define( 'DB_USER', ${db_wp_username} );
define( 'DB_PASSWORD', ${db_wp_password} );
define( 'DB_HOST', 'localhost' );
define( 'DB_CHARSET', 'utf8' );
define( 'DB_COLLATE', '' );
\$table_prefix = 'wp_';
if ( ! defined( 'ABSPATH' ) ) {
define( 'ABSPATH', __DIR__ . '/' );
}
require_once ABSPATH . 'wp-settings.php';
EOF
;;
2) #LAMP_L8
#!/bin/bash
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
composer create-project laravel/laravel /var/www/laravel
touch /etc/apache2/sites-available/laravel.conf
cat << EOF > /etc/apache2/sites-available/laravel.conf
<VirtualHost *:80>
ServerName laravel
DocumentRoot /var/www/laravel/public/
<Directory /var/www/laravel/public/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
Require all granted
</Directory>
LogLevel debug
ErrorLog /var/www/laravel/storage/logs/error.log
CustomLog /var/www/laravel/storage/logs/access.log combined
</VirtualHost>
EOF
sudo chown www-data /var/www/laravel/storage/framework/sessions/
sudo chown www-data /var/www/laravel/storage/framework/views/
sudo chown www-data /var/www/laravel/storage/logs/
rm /etc/apache2/sites-enabled/000-default.conf
ln -s /etc/apache2/sites-available/laravel.conf /etc/apache2/sites-enabled/
systemctl restart apache2
;;
3) #LAMP_Y2B
#!/bin/bash
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
composer create-project --prefer-dist yiisoft/yii2-app-basic /var/www/yii2basic
mkdir /var/www/yii2basic/log
chown www-data /var/www/yii2basic/log
touch /etc/apache2/sites-available/yii2basic.conf
cat << EOF > /etc/apache2/sites-available/yii2basic.conf
<VirtualHost *:80>
ServerName mysite
ServerAlias www.mysite
ServerAdmin webmaster@localhost
DocumentRoot /var/www/yii2basic/web
ErrorLog /var/www/yii2basic/log/error.log
CustomLog /var/www/yii2basic/log/access.log combined
<Directory "/var/www/yii2basic/web">
# use mod_rewrite for pretty URL support
RewriteEngine on
# if \$showScriptName is false in UrlManager, do not allow accessing URLs with script name
RewriteRule ^index.php/ - [L,R=404]
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php
# ...other settings...
</Directory>
</VirtualHost>
EOF
a2enmod rewrite
rm /etc/apache2/sites-enabled/000-default.conf
ln -s /etc/apache2/sites-available/yii2basic.conf /etc/apache2/sites-enabled/
systemctl restart apache2
;;
4) #LAMP_Y2A
#!/bin/bash
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
composer create-project --prefer-dist yiisoft/yii2-app-advanced /var/www/yii-application
cd /var/www/yii-application
sudo php init
mysql << EOF
create database yii2advanced;
exit;
EOF
php yii migrate
mkdir /var/www/yii-application/log
touch /var/www/yii-application/log/frontend-access.log
chown -R www-data /var/www/yii-application/log
touch /etc/apache2/sites-available/yii2adv.conf
cat << EOF > /etc/apache2/sites-available/yii2adv.conf
<VirtualHost *:80>
ServerName frontend
DocumentRoot "/var/www/yii-application/frontend/web/"
<Directory "/var/www/yii-application/frontend/web/">
# use mod_rewrite for pretty URL support
RewriteEngine on
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php
# use index.php as index file
DirectoryIndex index.php
# ...other settings...
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName backend
DocumentRoot "/var/www/yii-application/backend/web/"
<Directory "/var/www/yii-application/backend/web/">
# use mod_rewrite for pretty URL support
RewriteEngine on
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php
# use index.php as index file
DirectoryIndex index.php
# ...other settings...
</Directory>
</VirtualHost>
EOF
a2enmod rewrite
rm /etc/apache2/sites-enabled/000-default.conf
ln -s /etc/apache2/sites-available/yii2adv.conf /etc/apache2/sites-enabled/
systemctl restart apache2
;;
esac
chown ubuntu:ubuntu /var/www/ -R
chmod 755 /var/www/ -R