forked from littlebizzy/slickstack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathss-install-wordpress-config.txt
666 lines (522 loc) · 27.9 KB
/
ss-install-wordpress-config.txt
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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
#!/bin/bash
####################################################################################################
#### author: SlickStack ############################################################################
#### link: https://slickstack.io ###################################################################
#### mirror: https://mirrors.slickstack.io/bash/ss-install-wordpress-config.txt ####################
#### path: /var/www/ss-install-wordpress-config ####################################################
#### destination: n/a (not a boilerplate) ##########################################################
#### purpose: Reinstalls WordPress module (CMS) config files based on ss-config (idempotent) #######
#### module version: WordPress 6.0.x ###############################################################
#### sourced by: ss-install, ss-install-nginx-config ###############################################
#### bash aliases: ss install [wordpress|wp] config ################################################
####################################################################################################
## SS-CONFIG MUST BE PROPERLY CONFIGURED AND ON CURRENT BUILD BEFORE RUNNING SS-INSTALL ##
## ENSURE YOUR SS-CONFIG BUILD REMAINS CURRENT BY RUNNING SS-UPDATE OCCASIONALLY ##
## source ss-config ##
source /var/www/ss-config
## source ss-functions ##
source /var/www/ss-functions
## BELOW THIS RELIES ON SS-CONFIG AND SS-FUNCTIONS
####################################################################################################
#### TABLE OF CONTENTS (SS-Install-WordPress-Config) ###############################################
####################################################################################################
## this is a brief summary of the different code snippets you will find in this script ##
## each section should be commented so you understand what is being accomplished ##
## A. Touch Timestamp File
## B. Message (Begin Script)
## C. Install WP-Config.php (Production)
## D. Install WP-Config.php (Staging)
## E. Install WP-Config.php (Development)
## F. Modify Site Domains In Database
## G. Reset Permissions (WordPress Config)
## H. Purge Cache (PHP OPcache)
####################################################################################################
#### A. SS-Install-WordPress-Config: Touch Timestamp File ##########################################
####################################################################################################
## this is a dummy timestamp file that will remember the last time this script was run ##
## it can be useful for developer reference and is sometimes used by SlickStack ##
## script timestamp ##
ss_touch "${TIMESTAMP_SS_INSTALL_WORDPRESS_CONFIG}"
####################################################################################################
#### B. SS-Install-WordPress-Config: Message (Begin Script) ########################################
####################################################################################################
## this is a simple message that announces to the shell the purpose of this bash script ##
## it will only be noticed by sudo users who manually call ss core bash scripts ##
## echo message ##
ss_echo "${COLOR_INFO}Running ss-install-wordpress-config... ${COLOR_RESET}"
####################################################################################################
#### SS-Worker: Install Latest SS-Constants.php Boilerplate ########################################
####################################################################################################
## move to ss-install-php-config ??
## SNIPPET: ss-worker, ss-install-wordpress-config
## UPDATED:
## retrieve ss-constants.php boilerplate ##
ss_wget "${TMP_SS_CONSTANTS_PHP}" "${MIRROR_SS_CONSTANTS_PHP}"
VALIDATE_TMP_SS_CONSTANTS_PHP=$(grep 'SS_EOF' "${TMP_SS_CONSTANTS_PHP}" 2> /dev/null)
if [[ -z "${VALIDATE_TMP_SS_CONSTANTS_PHP}" ]]; then
ss_wget "${TMP_SS_CONSTANTS_PHP}" "${MIRROR2_SS_CONSTANTS_PHP}"
fi
VALIDATE2_TMP_SS_CONSTANTS_PHP=$(grep 'SS_EOF' "${TMP_SS_CONSTANTS_PHP}" 2> /dev/null)
if [[ -z "${VALIDATE2_TMP_SS_CONSTANTS_PHP}" ]]; then
ss_wget "${TMP_SS_CONSTANTS_PHP}" "${MIRROR3_SS_CONSTANTS_PHP}"
fi
## set SlickStack dashboard ##
if [[ -z "$SS_WORDPRESS_ADMIN_DASHBOARD" ]]; then
ss_sed "s/@SS_WORDPRESS_ADMIN_DASHBOARD/true/g" "$TMP_SS_CONSTANTS_PHP"
else
ss_sed "s/@SS_WORDPRESS_ADMIN_DASHBOARD/${SS_WORDPRESS_ADMIN_DASHBOARD}/g" "$TMP_SS_CONSTANTS_PHP"
fi
SYSTEM_SERVER_SOFTWARE=$(nginx -v |& sed 's#nginx version: nginx/##')
SYSTEM_MYSQL_SIZE=$(du -sh /var/lib/mysql |& sed 's#/var/lib/mysql##')
SYSTEM_MYSQL_VERSION=$(mysql --version |& awk '{print $3}')
ss_sed "s|@SYSTEM_VENDOR|${SYSTEM_VENDOR}|g" "$TMP_SS_CONSTANTS_PHP"
ss_sed "s|@SYSTEM_VIRTUAL|${SYSTEM_VIRTUAL}|g" "$TMP_SS_CONSTANTS_PHP"
ss_sed "s|@SYSTEM_LINUX_KERNEL|${SYSTEM_LINUX_KERNEL}|g" "$TMP_SS_CONSTANTS_PHP"
ss_sed "s|@SYSTEM_CPU_CORES|${SYSTEM_CPU_CORES}|g" "$TMP_SS_CONSTANTS_PHP"
ss_sed "s|@SYSTEM_OS_PRETTY_NAME|${SYSTEM_OS_PRETTY_NAME}|g" "$TMP_SS_CONSTANTS_PHP"
if [[ "${SS_DATABASE_REMOTE}" != "false" ]]; then
ss_sed "/MYSQL_VERSION/d" "${TMP_SS_CONSTANTS_PHP}"
else
ss_sed "s|@SYSTEM_MYSQL_VERSION|${SYSTEM_MYSQL_VERSION}|g" "${TMP_SS_CONSTANTS_PHP}"
fi
if [[ "${SS_DATABASE_REMOTE}" != "false" ]]; then
ss_sed "/MYSQL_SIZE/d" "${TMP_SS_CONSTANTS_PHP}"
else
ss_sed "s|@SYSTEM_MYSQL_SIZE|${SYSTEM_MYSQL_SIZE}|g" "${TMP_SS_CONSTANTS_PHP}"
fi
ss_sed "s|@SYSTEM_DISK_FREE|${SYSTEM_DISK_FREE}|g" "$TMP_SS_CONSTANTS_PHP"
ss_sed "s|@SYSTEM_DISK_TOTAL|${SYSTEM_DISK_TOTAL}|g" "$TMP_SS_CONSTANTS_PHP"
ss_sed "s|@SYSTEM_IPV4_ADDRESS|${SYSTEM_IPV4_ADDRESS}|g" "$TMP_SS_CONSTANTS_PHP"
ss_sed "s|@SYSTEM_IPV6_ADDRESS|${SYSTEM_IPV6_ADDRESS}|g" "$TMP_SS_CONSTANTS_PHP"
ss_sed "s|@SYSTEM_HOSTNAME|${SYSTEM_HOSTNAME}|g" "$TMP_SS_CONSTANTS_PHP"
ss_sed "s|@SYSTEM_SERVER_SOFTWARE|${SYSTEM_SERVER_SOFTWARE}|g" "$TMP_SS_CONSTANTS_PHP"
SYSTEM_PHP_VERSION=$(php -v | awk '/^PHP/{print $2}')
# SYSTEM_PHP_EXTENSIONS
ss_sed "s|@SYSTEM_PHP_VERSION|${SYSTEM_PHP_VERSION}|g" "$TMP_SS_CONSTANTS_PHP"
ss_sed "s|@SYSTEM_PHP_EXTENSIONS|${SYSTEM_PHP_EXTENSIONS}|g" "$TMP_SS_CONSTANTS_PHP"
VALIDATE_TMP_SS_CONSTANTS_PHP=$(grep 'SS_EOF' "$TMP_SS_CONSTANTS_PHP")
if [[ -n "$VALIDATE_TMP_SS_CONSTANTS_PHP" ]]; then
cp "$TMP_SS_CONSTANTS_PHP" "$PATH_SS_CONSTANTS_PHP"
chown www-data:www-data "$PATH_SS_CONSTANTS_PHP"
chmod 0440 "$PATH_SS_CONSTANTS_PHP" ## 0440 (read-only)
fi
## run this because ss-constants.php has some temp fixes to replaced @placeholders ##
## run ss-worker ##
source "$PATH_SS_WORKER"
## remove this after above snippet synced with snippet in ss-worker
####################################################################################################
#### C. SS-Install-WordPress-Config: Install WP-Config.php (Production) ############################
####################################################################################################
## here we retrieve latest wp-config.php boilerplate and customize per ss-config settings ##
## you should never make changes directly to wp-config.php on SlickStack servers ##
## retrieve latest boilerplate (production) ##
if [[ "${WP_MULTISITE}" == "true" ]] && [[ "${WP_MULTISITE_SUBDOMAINS}" != "false" ]]; then
ss_wget "${TMP_WP_CONFIG_PHP}" "${MIRROR_WP_CONFIG_PHP_PRODUCTION_MULTISITE_SUBDOMAINS}"
else
ss_wget "${TMP_WP_CONFIG_PHP}" "${MIRROR_WP_CONFIG_PHP_PRODUCTION_SINGLE_SITE}"
fi
## THIS MUST COME BEFORE WP_MULTISITE REPLACEMENTS OTHERWISE IT WILL BE OVERWRITTEN ##
## in the future fix this to have a more unique set of placeholders ##
## set multisite subdomains ##
if [[ "${WP_MULTISITE_SUBDOMAINS}" == "false" ]]; then
ss_sed "s/@WP_MULTISITE_SUBDOMAINS/false/g" "${TMP_WP_CONFIG_PHP}"
else
ss_sed "s/@WP_MULTISITE_SUBDOMAINS/true/g" "${TMP_WP_CONFIG_PHP}"
fi
## set multisite ##
if [[ "$WP_MULTISITE" == "true" ]]; then
ss_sed "s/@WP_MULTISITE/true/g" "${TMP_WP_CONFIG_PHP}"
else
ss_sed "s/@WP_MULTISITE/false/g" "${TMP_WP_CONFIG_PHP}"
fi
## set wp cron (always disabled in wp-config for staging and dev sites in slickstack servers) ##
if [[ "$WP_CRON_METHOD" == "server" ]]; then
ss_sed "s/@DISABLE_WP_CRON/true/g" "${TMP_WP_CONFIG_PHP}"
else
ss_sed "s/@DISABLE_WP_CRON/false/g" "${TMP_WP_CONFIG_PHP}"
fi
## replace database placeholders ##
ss_sed "s/@DB_NAME/${DB_NAME}/g" "${TMP_WP_CONFIG_PHP}"
ss_sed "s/@DB_USER/${DB_USER}/g" "${TMP_WP_CONFIG_PHP}"
ss_sed "s/@DB_PASSWORD/${DB_PASSWORD}/g" "${TMP_WP_CONFIG_PHP}"
ss_sed "s/@DB_HOST/${DB_HOST}/g" "${TMP_WP_CONFIG_PHP}"
if [[ "${SS_DATABASE_REMOTE}" == "true" ]]; then
ss_sed "s/@DB_PORT/${DB_PORT}/g" "${TMP_WP_CONFIG_PHP}"
else
ss_sed "s/@DB_PORT/3306/g" "${TMP_WP_CONFIG_PHP}"
fi
ss_sed "s/@DB_CHARSET/${DB_CHARSET}/g" "${TMP_WP_CONFIG_PHP}"
ss_sed "s/@DB_COLLATE/${DB_COLLATE}/g" "${TMP_WP_CONFIG_PHP}"
ss_sed "s/@DB_PREFIX/${DB_PREFIX}/g" "${TMP_WP_CONFIG_PHP}"
## set object cache (optional) ##
if [[ -z "$OBJECT_CACHE" ]]; then
ss_sed "s/@OBJECT_CACHE/true/g" "${TMP_WP_CONFIG_PHP}"
else
ss_sed "s/@OBJECT_CACHE/${OBJECT_CACHE}/g" "${TMP_WP_CONFIG_PHP}"
fi
## set domains ##
ss_sed "s/@SITE_DOMAIN/${SITE_DOMAIN}/g" "${TMP_WP_CONFIG_PHP}"
ss_sed "s/@SITE_TLD/${SITE_TLD}/g" "${TMP_WP_CONFIG_PHP}"
## set SFTP ##
ss_sed "s/@SFTP_USER/${SFTP_USER}/g" "${TMP_WP_CONFIG_PHP}"
ss_sed "s/@SFTP_PASSWORD/${SFTP_PASSWORD}/g" "${TMP_WP_CONFIG_PHP}"
if [[ -z "$SSH_PORT" ]]; then
ss_sed "s/@SSH_PORT/6969/g" "${TMP_WP_CONFIG_PHP}"
else
ss_sed "s/@SSH_PORT/${SSH_PORT}/g" "${TMP_WP_CONFIG_PHP}"
fi
## set salts ##
ss_sed "s/@AUTHKEY/$(openssl rand -hex 48)/g" "${TMP_WP_CONFIG_PHP}"
ss_sed "s/@SECUREAUTHKEY/$(openssl rand -hex 48)/g" "${TMP_WP_CONFIG_PHP}"
ss_sed "s/@LOGGEDINKEY/$(openssl rand -hex 48)/g" "${TMP_WP_CONFIG_PHP}"
ss_sed "s/@NONCEKEY/$(openssl rand -hex 48)/g" "${TMP_WP_CONFIG_PHP}"
ss_sed "s/@AUTHSALT/$(openssl rand -hex 48)/g" "${TMP_WP_CONFIG_PHP}"
ss_sed "s/@SECUREAUTHSALT/$(openssl rand -hex 48)/g" "${TMP_WP_CONFIG_PHP}"
ss_sed "s/@LOGGEDINSALT/$(openssl rand -hex 48)/g" "${TMP_WP_CONFIG_PHP}"
ss_sed "s/@NONCESALT/$(openssl rand -hex 48)/g" "${TMP_WP_CONFIG_PHP}"
## environment ##
ss_sed "s/@WP_LOCAL_DEV/false/g" "${TMP_WP_CONFIG_PHP}"
## core auto updates ##
if [[ -z "$WP_AUTO_UPDATE_CORE" ]]; then
ss_sed "s/@WP_AUTO_UPDATE_CORE/minor/g" "${TMP_WP_CONFIG_PHP}"
else
ss_sed "s/@WP_AUTO_UPDATE_CORE/${WP_AUTO_UPDATE_CORE}/g" "${TMP_WP_CONFIG_PHP}"
fi
## autosave (drafts) ##
if [[ -z "$WP_AUTOSAVE_INTERVAL" ]]; then
ss_sed "s/@WP_AUTOSAVE_INTERVAL/60/g" "${TMP_WP_CONFIG_PHP}"
else
ss_sed "s/@WP_AUTOSAVE_INTERVAL/${WP_AUTOSAVE_INTERVAL}/g" "${TMP_WP_CONFIG_PHP}"
fi
## default theme ##
if [[ -z "${WP_DEFAULT_THEME}" ]]; then
ss_sed "s/@WP_DEFAULT_THEME/twentytwenty/g" "${TMP_WP_CONFIG_PHP}"
else
ss_sed "s/@WP_DEFAULT_THEME/${WP_DEFAULT_THEME}/g" "${TMP_WP_CONFIG_PHP}"
fi
## revisions ##
if [[ -z "$WP_POST_REVISIONS" ]]; then
ss_sed "s/@WP_POST_REVISIONS/5/g" "${TMP_WP_CONFIG_PHP}"
else
ss_sed "s/@WP_POST_REVISIONS/${WP_POST_REVISIONS}/g" "${TMP_WP_CONFIG_PHP}"
fi
## block external requests ##
if [[ -z "$WP_HTTP_BLOCK_EXTERNAL" ]]; then
ss_sed "s/@WP_HTTP_BLOCK_EXTERNAL/false/g" "${TMP_WP_CONFIG_PHP}"
else
ss_sed "s/@WP_HTTP_BLOCK_EXTERNAL/${WP_HTTP_BLOCK_EXTERNAL}/g" "${TMP_WP_CONFIG_PHP}"
fi
## allowed hosts ##
if [[ -z "$WP_ACCESSIBLE_HOSTS" ]]; then
ss_sed "s/@WP_ACCESSIBLE_HOSTS/api.wordpress.org/g" "${TMP_WP_CONFIG_PHP}"
else
ss_sed "s/@WP_ACCESSIBLE_HOSTS/${WP_ACCESSIBLE_HOSTS}/g" "${TMP_WP_CONFIG_PHP}"
fi
## file edits ##
if [[ -z "$WP_DISALLOW_FILE_EDIT" ]]; then
ss_sed "s/@WP_DISALLOW_FILE_EDIT/false/g" "${TMP_WP_CONFIG_PHP}"
else
ss_sed "s/@WP_DISALLOW_FILE_EDIT/${WP_DISALLOW_FILE_EDIT}/g" "${TMP_WP_CONFIG_PHP}"
fi
## file mods ##
if [[ -z "$WP_DISALLOW_FILE_MODS" ]]; then
ss_sed "s/@WP_DISALLOW_FILE_MODS/false/g" "${TMP_WP_CONFIG_PHP}"
else
ss_sed "s/@WP_DISALLOW_FILE_MODS/${WP_DISALLOW_FILE_MODS}/g" "${TMP_WP_CONFIG_PHP}"
fi
## file uploads ##
if [[ -z "$WP_ALLOW_UNFILTERED_UPLOADS" ]]; then
ss_sed "s/@WP_ALLOW_UNFILTERED_UPLOADS/true/g" "${TMP_WP_CONFIG_PHP}"
else
ss_sed "s/@WP_ALLOW_UNFILTERED_UPLOADS/${WP_ALLOW_UNFILTERED_UPLOADS}/g" "${TMP_WP_CONFIG_PHP}"
fi
## for fresh (virgin) WP installs enable certain items ##
if [ ! -f "/var/www/meta/.cherry" ]; then
ss_sed "s#//VIRGIN//##g" "${TMP_WP_CONFIG_PHP}"
fi
## copy files to destinations (if valid) ##
VALIDATE_TMP_WP_CONFIG_PHP=$(grep 'SS_EOF' "${TMP_WP_CONFIG_PHP}")
if [[ -n "$VALIDATE_TMP_WP_CONFIG_PHP" ]]; then
ss_mv "${TMP_WP_CONFIG_PHP}" "${PATH_WP_CONFIG_PHP}"
else
echo -e "${COLOR_ERROR}wp config temp file for production damaged so not installing... ${COLOR_RESET}"
fi
####################################################################################################
#### D. SS-Install-WordPress-Config: Install WP-Config.php (Staging) ###############################
####################################################################################################
## here we retrieve latest wp-config.php boilerplate and customize per ss-config settings ##
## you should never make changes directly to wp-config.php in SlickStack servers ##
if [[ "${STAGING_SITE}" == "true" ]]; then
## retrieve latest boilerplate (staging) ##
ss_wget "${TMP_WORDPRESS_CONFIG_STAGING}" "${MIRROR_WP_CONFIG_STAGING}"
###### WP Multisite settings ########
## set multisite subdomains ##
if [[ "$WP_MULTISITE_SUBDOMAINS" == "false" ]]; then
ss_sed "s/@WP_MULTISITE_SUBDOMAINS/false/g" "${TMP_WORDPRESS_CONFIG_STAGING}"
else
ss_sed "s/@WP_MULTISITE_SUBDOMAINS/true/g" "${TMP_WORDPRESS_CONFIG_STAGING}"
fi
## set multisite ##
if [[ "$WP_MULTISITE" == "true" ]]; then
ss_sed "s/@WP_MULTISITE/true/g" "${TMP_WORDPRESS_CONFIG_STAGING}"
else
ss_sed "s/@WP_MULTISITE/false/g" "${TMP_WORDPRESS_CONFIG_STAGING}"
fi
####### other WP Config settings ##########
## replace database placeholders ##
# ss_sed "s/@DB_NAME/${DB_NAME}/g" "${TMP_WORDPRESS_CONFIG_STAGING}"
ss_sed "s/@DB_USER/${DB_USER}/g" "${TMP_WORDPRESS_CONFIG_STAGING}"
ss_sed "s/@DB_PASSWORD/${DB_PASSWORD}/g" "${TMP_WORDPRESS_CONFIG_STAGING}"
ss_sed "s/@DB_HOST/${DB_HOST}/g" "${TMP_WORDPRESS_CONFIG_STAGING}"
if [[ "${SS_DATABASE_REMOTE}" == "true" ]]; then
ss_sed "s/@DB_PORT/${DB_PORT}/g" "${TMP_WORDPRESS_CONFIG_STAGING}"
else
ss_sed "s/@DB_PORT/3306/g" "${TMP_WORDPRESS_CONFIG_STAGING}"
fi
ss_sed "s/@DB_CHARSET/${DB_CHARSET}/g" "${TMP_WORDPRESS_CONFIG_STAGING}"
ss_sed "s/@DB_COLLATE/${DB_COLLATE}/g" "${TMP_WORDPRESS_CONFIG_STAGING}"
ss_sed "s/@DB_PREFIX/${DB_PREFIX}/g" "${TMP_WORDPRESS_CONFIG_STAGING}"
## disable object cache (staging) ##
ss_sed "s/@OBJECT_CACHE/false/g" "${TMP_WORDPRESS_CONFIG_STAGING}"
## replace domain placeholders ##
ss_sed "s#@SITE_DOMAIN#${SITE_DOMAIN_EXCLUDING_WWW}#g" "${TMP_WORDPRESS_CONFIG_STAGING}"
ss_sed "s/@SITE_TLD/${SITE_TLD}/g" "${TMP_WORDPRESS_CONFIG_STAGING}"
## replace SFTP Details placeholders ##
ss_sed "s/@SFTP_USER/${SFTP_USER}/g" "${TMP_WORDPRESS_CONFIG_STAGING}"
ss_sed "s/@SFTP_PASSWORD/${SFTP_PASSWORD}/g" "${TMP_WORDPRESS_CONFIG_STAGING}"
if [[ -z "$SSH_PORT" ]]; then
ss_sed "s/@SSH_PORT/6969/g" "${TMP_WORDPRESS_CONFIG_STAGING}"
else
ss_sed "s/@SSH_PORT/${SSH_PORT}/g" "${TMP_WORDPRESS_CONFIG_STAGING}"
fi
## replace salt keys ##
ss_sed "s/@AUTHKEY/$(openssl rand -hex 48)/g" "${TMP_WORDPRESS_CONFIG_STAGING}"
ss_sed "s/@SECUREAUTHKEY/$(openssl rand -hex 48)/g" "${TMP_WORDPRESS_CONFIG_STAGING}"
ss_sed "s/@LOGGEDINKEY/$(openssl rand -hex 48)/g" "${TMP_WORDPRESS_CONFIG_STAGING}"
ss_sed "s/@NONCEKEY/$(openssl rand -hex 48)/g" "${TMP_WORDPRESS_CONFIG_STAGING}"
ss_sed "s/@AUTHSALT/$(openssl rand -hex 48)/g" "${TMP_WORDPRESS_CONFIG_STAGING}"
ss_sed "s/@SECUREAUTHSALT/$(openssl rand -hex 48)/g" "${TMP_WORDPRESS_CONFIG_STAGING}"
ss_sed "s/@LOGGEDINSALT/$(openssl rand -hex 48)/g" "${TMP_WORDPRESS_CONFIG_STAGING}"
ss_sed "s/@NONCESALT/$(openssl rand -hex 48)/g" "${TMP_WORDPRESS_CONFIG_STAGING}"
## environment ##
ss_sed "s/@WP_LOCAL_DEV/false/g" "${TMP_WORDPRESS_CONFIG_STAGING}"
## core auto updates ##
if [[ -z "$WP_AUTO_UPDATE_CORE" ]]; then
ss_sed "s/@WP_AUTO_UPDATE_CORE/minor/g" "${TMP_WORDPRESS_CONFIG_STAGING}"
else
ss_sed "s/@WP_AUTO_UPDATE_CORE/${WP_AUTO_UPDATE_CORE}/g" "${TMP_WORDPRESS_CONFIG_STAGING}"
fi
## autosave (drafts) ##
if [[ -z "$WP_AUTOSAVE_INTERVAL" ]]; then
ss_sed "s/@WP_AUTOSAVE_INTERVAL/60/g" "${TMP_WORDPRESS_CONFIG_STAGING}"
else
ss_sed "s/@WP_AUTOSAVE_INTERVAL/${WP_AUTOSAVE_INTERVAL}/g" "${TMP_WORDPRESS_CONFIG_STAGING}"
fi
## default theme ##
if [[ -z "${WP_DEFAULT_THEME}" ]]; then
ss_sed "s/@WP_DEFAULT_THEME/twentytwenty/g" "${TMP_WORDPRESS_CONFIG_STAGING}"
else
ss_sed "s/@WP_DEFAULT_THEME/${WP_DEFAULT_THEME}/g" "${TMP_WORDPRESS_CONFIG_STAGING}"
fi
## revisions ##
if [[ -z "$WP_POST_REVISIONS" ]]; then
ss_sed "s/@WP_POST_REVISIONS/5/g" "${TMP_WORDPRESS_CONFIG_STAGING}"
else
ss_sed "s/@WP_POST_REVISIONS/${WP_POST_REVISIONS}/g" "${TMP_WORDPRESS_CONFIG_STAGING}"
fi
## block external requests ##
if [[ -z "$WP_HTTP_BLOCK_EXTERNAL" ]]; then
ss_sed "s/@WP_HTTP_BLOCK_EXTERNAL/false/g" "${TMP_WORDPRESS_CONFIG_STAGING}"
else
ss_sed "s/@WP_HTTP_BLOCK_EXTERNAL/${WP_HTTP_BLOCK_EXTERNAL}/g" "${TMP_WORDPRESS_CONFIG_STAGING}"
fi
## allowed hosts ##
if [[ -z "$WP_ACCESSIBLE_HOSTS" ]]; then
ss_sed "s/@WP_ACCESSIBLE_HOSTS/api.wordpress.org/g" "${TMP_WORDPRESS_CONFIG_STAGING}"
else
ss_sed "s/@WP_ACCESSIBLE_HOSTS/${WP_ACCESSIBLE_HOSTS}/g" "${TMP_WORDPRESS_CONFIG_STAGING}"
fi
## file edits ##
ss_sed "s/@WP_DISALLOW_FILE_EDIT/false/g" "${TMP_WORDPRESS_CONFIG_STAGING}"
## file mods ##
ss_sed "s/@WP_DISALLOW_FILE_MODS/false/g" "${TMP_WORDPRESS_CONFIG_STAGING}"
## file uploads ##
if [[ -z "$WP_ALLOW_UNFILTERED_UPLOADS" ]]; then
ss_sed "s/@WP_ALLOW_UNFILTERED_UPLOADS/true/g" "${TMP_WORDPRESS_CONFIG_STAGING}"
else
ss_sed "s/@WP_ALLOW_UNFILTERED_UPLOADS/${WP_ALLOW_UNFILTERED_UPLOADS}/g" "${TMP_WORDPRESS_CONFIG_STAGING}"
fi
## install files ##
ss_mv "${TMP_WORDPRESS_CONFIG_STAGING}" /var/www/html/staging/wp-config.php
fi
####################################################################################################
#### E. SS-Install-WordPress-Config: Install WP-Config.php (Development) ###########################
####################################################################################################
## here we retrieve latest wp-config.php boilerplate and customize per ss-config settings ##
## you should never make changes directly to wp-config.php in SlickStack servers ##
if [[ "${DEV_SITE}" == "true" ]]; then
## retrieve latest boilerplate (dev) ##
ss_wget "${TMP_WORDPRESS_CONFIG_DEV}" "${MIRROR_WP_CONFIG_DEV}"
###### WP Multisite settings ########
## set multisite subdomains ##
if [[ "$WP_MULTISITE_SUBDOMAINS" == "false" ]]; then
ss_sed "s/@WP_MULTISITE_SUBDOMAINS/false/g" "${TMP_WORDPRESS_CONFIG_DEV}"
else
ss_sed "s/@WP_MULTISITE_SUBDOMAINS/true/g" "${TMP_WORDPRESS_CONFIG_DEV}"
fi
## set multisite ##
if [[ "$WP_MULTISITE" == "true" ]]; then
ss_sed "s/@WP_MULTISITE/true/g" "${TMP_WORDPRESS_CONFIG_DEV}"
else
ss_sed "s/@WP_MULTISITE/false/g" "${TMP_WORDPRESS_CONFIG_DEV}"
fi
####### other WP Config settings ##########
## replace database placeholders ##
# ss_sed "s/@DB_NAME/${DB_NAME}/g" "${TMP_WORDPRESS_CONFIG_DEV}"
ss_sed "s/@DB_USER/${DB_USER}/g" "${TMP_WORDPRESS_CONFIG_DEV}"
ss_sed "s/@DB_PASSWORD/${DB_PASSWORD}/g" "${TMP_WORDPRESS_CONFIG_DEV}"
ss_sed "s/@DB_HOST/${DB_HOST}/g" "${TMP_WORDPRESS_CONFIG_DEV}"
if [[ "${SS_DATABASE_REMOTE}" == "true" ]]; then
ss_sed "s/@DB_PORT/${DB_PORT}/g" "${TMP_WORDPRESS_CONFIG_DEV}"
else
ss_sed "s/@DB_PORT/3306/g" "${TMP_WORDPRESS_CONFIG_DEV}"
fi
ss_sed "s/@DB_CHARSET/${DB_CHARSET}/g" "${TMP_WORDPRESS_CONFIG_DEV}"
ss_sed "s/@DB_COLLATE/${DB_COLLATE}/g" "${TMP_WORDPRESS_CONFIG_DEV}"
ss_sed "s/@DB_PREFIX/${DB_PREFIX}/g" "${TMP_WORDPRESS_CONFIG_DEV}"
## disable object cache (staging) ##
ss_sed "s/@OBJECT_CACHE/false/g" "${TMP_WORDPRESS_CONFIG_DEV}"
## replace domain placeholders ##
ss_sed "s#@SITE_DOMAIN#${SITE_DOMAIN_EXCLUDING_WWW}#g" "${TMP_WORDPRESS_CONFIG_DEV}"
ss_sed "s/@SITE_TLD/${SITE_TLD}/g" "${TMP_WORDPRESS_CONFIG_DEV}"
## replace SFTP Details placeholders ##
ss_sed "s/@SFTP_USER/${SFTP_USER}/g" "${TMP_WORDPRESS_CONFIG_DEV}"
ss_sed "s/@SFTP_PASSWORD/${SFTP_PASSWORD}/g" "${TMP_WORDPRESS_CONFIG_DEV}"
if [[ -z "$SSH_PORT" ]]; then
ss_sed "s/@SSH_PORT/6969/g" "${TMP_WORDPRESS_CONFIG_DEV}"
else
ss_sed "s/@SSH_PORT/${SSH_PORT}/g" "${TMP_WORDPRESS_CONFIG_DEV}"
fi
## replace salt keys ##
ss_sed "s/@AUTHKEY/$(openssl rand -hex 48)/g" "${TMP_WORDPRESS_CONFIG_DEV}"
ss_sed "s/@SECUREAUTHKEY/$(openssl rand -hex 48)/g" "${TMP_WORDPRESS_CONFIG_DEV}"
ss_sed "s/@LOGGEDINKEY/$(openssl rand -hex 48)/g" "${TMP_WORDPRESS_CONFIG_DEV}"
ss_sed "s/@NONCEKEY/$(openssl rand -hex 48)/g" "${TMP_WORDPRESS_CONFIG_DEV}"
ss_sed "s/@AUTHSALT/$(openssl rand -hex 48)/g" "${TMP_WORDPRESS_CONFIG_DEV}"
ss_sed "s/@SECUREAUTHSALT/$(openssl rand -hex 48)/g" "${TMP_WORDPRESS_CONFIG_DEV}"
ss_sed "s/@LOGGEDINSALT/$(openssl rand -hex 48)/g" "${TMP_WORDPRESS_CONFIG_DEV}"
ss_sed "s/@NONCESALT/$(openssl rand -hex 48)/g" "${TMP_WORDPRESS_CONFIG_DEV}"
## environment ##
ss_sed "s/@WP_LOCAL_DEV/false/g" "${TMP_WORDPRESS_CONFIG_DEV}"
## core auto updates ##
if [[ -z "$WP_AUTO_UPDATE_CORE" ]]; then
ss_sed "s/@WP_AUTO_UPDATE_CORE/minor/g" "${TMP_WORDPRESS_CONFIG_DEV}"
else
ss_sed "s/@WP_AUTO_UPDATE_CORE/${WP_AUTO_UPDATE_CORE}/g" "${TMP_WORDPRESS_CONFIG_DEV}"
fi
## autosave (drafts) ##
if [[ -z "$WP_AUTOSAVE_INTERVAL" ]]; then
ss_sed "s/@WP_AUTOSAVE_INTERVAL/60/g" "${TMP_WORDPRESS_CONFIG_DEV}"
else
ss_sed "s/@WP_AUTOSAVE_INTERVAL/${WP_AUTOSAVE_INTERVAL}/g" "${TMP_WORDPRESS_CONFIG_DEV}"
fi
## default theme ##
if [[ -z "${WP_DEFAULT_THEME}" ]]; then
ss_sed "s/@WP_DEFAULT_THEME/twentytwenty/g" "${TMP_WORDPRESS_CONFIG_DEV}"
else
ss_sed "s/@WP_DEFAULT_THEME/${WP_DEFAULT_THEME}/g" "${TMP_WORDPRESS_CONFIG_DEV}"
fi
## revisions ##
if [[ -z "$WP_POST_REVISIONS" ]]; then
ss_sed "s/@WP_POST_REVISIONS/5/g" "${TMP_WORDPRESS_CONFIG_DEV}"
else
ss_sed "s/@WP_POST_REVISIONS/${WP_POST_REVISIONS}/g" "${TMP_WORDPRESS_CONFIG_DEV}"
fi
## block external requests ##
if [[ -z "$WP_HTTP_BLOCK_EXTERNAL" ]]; then
ss_sed "s/@WP_HTTP_BLOCK_EXTERNAL/false/g" "${TMP_WORDPRESS_CONFIG_DEV}"
else
ss_sed "s/@WP_HTTP_BLOCK_EXTERNAL/${WP_HTTP_BLOCK_EXTERNAL}/g" "${TMP_WORDPRESS_CONFIG_DEV}"
fi
## allowed hosts ##
if [[ -z "$WP_ACCESSIBLE_HOSTS" ]]; then
ss_sed "s/@WP_ACCESSIBLE_HOSTS/api.wordpress.org/g" "${TMP_WORDPRESS_CONFIG_DEV}"
else
ss_sed "s/@WP_ACCESSIBLE_HOSTS/${WP_ACCESSIBLE_HOSTS}/g" "${TMP_WORDPRESS_CONFIG_DEV}"
fi
## file edits ##
ss_sed "s/@WP_DISALLOW_FILE_EDIT/false/g" "${TMP_WORDPRESS_CONFIG_DEV}"
## file mods ##
ss_sed "s/@WP_DISALLOW_FILE_MODS/false/g" "${TMP_WORDPRESS_CONFIG_DEV}"
## file uploads ##
if [[ -z "$WP_ALLOW_UNFILTERED_UPLOADS" ]]; then
ss_sed "s/@WP_ALLOW_UNFILTERED_UPLOADS/true/g" "${TMP_WORDPRESS_CONFIG_DEV}"
else
ss_sed "s/@WP_ALLOW_UNFILTERED_UPLOADS/${WP_ALLOW_UNFILTERED_UPLOADS}/g" "${TMP_WORDPRESS_CONFIG_DEV}"
fi
## copy files to destinations ##
cp "${TMP_WORDPRESS_CONFIG_DEV}" /var/www/html/dev/wp-config.php
fi
####################################################################################################
#### F. SS-Install-WordPress-Config: Modify Site Domains In Database ###############################
####################################################################################################
## here we manually fix certain fields in the database to ensure proper functionality ##
## this fix required for WP Multisite (wp-config.php enough for single sites) ##
## SNIPPET: ss-install-wordpress-config, ss-install-wordpress-core
## UPDATED: 05JUN2022
## production ##
if [[ -n $(mysql --execute "SHOW TABLES FROM ${DB_NAME} WHERE Tables_in_${DB_NAME} LIKE '${DB_PREFIX}options';" 2> /dev/null) ]]; then
mysql --execute="UPDATE ${DB_NAME}.${DB_PREFIX}options SET option_value='https://${SITE_DOMAIN}' WHERE option_name='home'";
mysql --execute="UPDATE ${DB_NAME}.${DB_PREFIX}options SET option_value='https://${SITE_DOMAIN}' WHERE option_name='siteurl'";
fi
## staging ##
if [[ "${STAGING_SITE}" == "true" ]]; then
if [[ -n $(mysql --execute "SHOW TABLES FROM staging WHERE Tables_in_staging LIKE '${DB_PREFIX}options';" 2> /dev/null) ]]; then
mysql --execute="UPDATE staging.${DB_PREFIX}options SET option_value='https://staging.${SITE_DOMAIN_EXCLUDING_WWW}' WHERE option_name='home'";
mysql --execute="UPDATE staging.${DB_PREFIX}options SET option_value='https://staging.${SITE_DOMAIN_EXCLUDING_WWW}' WHERE option_name='siteurl'";
fi
fi
## development ##
if [[ "${DEV_SITE}" == "true" ]]; then
if [[ -n $(mysql --execute "SHOW TABLES FROM development WHERE Tables_in_development LIKE '${DB_PREFIX}options';" 2> /dev/null) ]]; then
mysql --execute="UPDATE development.${DB_PREFIX}options SET option_value='https://dev.${SITE_DOMAIN_EXCLUDING_WWW}' WHERE option_name='home'";
mysql --execute="UPDATE development.${DB_PREFIX}options SET option_value='https://dev.${SITE_DOMAIN_EXCLUDING_WWW}' WHERE option_name='siteurl'";
fi
fi
####################################################################################################
#### G. SS-Install-WordPress-Config: Reset Permissions (WordPress Config) ##########################
####################################################################################################
## here we briefly reset permissions for the wp-config.php file and related dirs only ##
## keep in mind that general WordPress Core and other files are not affected ##
## run ss-perms-wordpress-config ##
source "${PATH_SS_PERMS_WORDPRESS_CONFIG}"
####################################################################################################
#### H. SS-Install-WordPress-Config: Purge Cache (PHP OPcache) #####################################
####################################################################################################
## run ss-purge-opcache ##
source "${PATH_SS_PURGE_OPCACHE}"
####################################################################################################
#### PLACEHOLDER: Reset Permissions (SlickStack Scripts) ###########################################
####################################################################################################
## we include this permissions reset in all cron jobs and bash scripts for redundancy ##
## chmod 0700 means only the root/sudo users can execute any SlickStack scripts ##
## THIS SNIPPET DOES NOT RELY ON SS-CONFIG OR SS-FUNCTIONS
## SNIPPET: ss bash scripts, ss cron jobs
## UPDATED: 02JUL2022
chown root:root /var/www/ss* ## must be root:root
chown root:root /var/www/crons/*cron* ## must be root:root
chown root:root /var/www/crons/custom/*cron* ## must be root:root
chmod 0700 /var/www/ss* ## 0700 means only root/sudo can execute
chmod 0700 /var/www/crons/*cron* ## 0700 means only root/sudo can execute
chmod 0700 /var/www/crons/custom/*cron* ## 0700 means only root/sudo can execute
####################################################################################################
#### SlickStack: External References Used To Improve This Script (Thanks, Interwebz) ###############
####################################################################################################
## Ref: https://wordpress.stackexchange.com/questions/281814/why-is-wordpress-multisite-redirecting-to-wp-signup-php-and-how-to-fix-it
## Ref: https://stackoverflow.com/questions/9366816/sed-fails-with-unknown-option-to-s-error
## Ref: https://superuser.com/questions/393812/supresss-the-no-such-file-or-directory-message-from-find
## Ref: https://stackoverflow.com/questions/45575021/find-suppress-no-such-file-or-directory-errors
## Ref: https://github.com/littlebizzy/slickstack/issues/100
## Ref: https://www.mysqltutorial.org/mysql-show-tables/
## Ref: https://stackoverflow.com/questions/32523635/two-wordpress-sites-using-diiferent-themes-on-the-same-database
## SS_EOF