#!/bin/bash #################################################################################################### #### author: SlickStack ############################################################################ #### link: https://slickstack.io ################################################################### #### mirror: http://mirrors.slickstack.io/bash/ss-install-wordpress-core.txt ####################### #### path: /var/www/ss-install-wordpress-core ###################################################### #### destination: n/a (not a boilerplate) ########################################################## #### purpose: Reinstalls the WordPress module (CMS) package and non-config files (idempotent) ###### #### module version: WordPress 5.5.x ############################################################### #### sourced by: ss-install, ss-install-wordpress ################################################## #### bash aliases: ss install wordpress core, ss install wp core ################################### #################################################################################################### ## 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 ## ## include SlickStack configuration ## source /var/www/ss-config ## include SlickStack functions ## source /var/www/ss-functions #################################################################################################### #### SS-Install-WordPress-Core: 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 ## echo -e "${PURPLE}Running ss-install-wordpress-core: Reinstalls the WordPress module (CMS) package and non-config files (idempotent)... ${NOCOLOR}" sleep "$SLEEP_MESSAGE_BEGIN" #################################################################################################### #### SS-Install-WordPress-Core: Enable Maintenance Mode (Via SS-Maintenance-Enable) ################ #################################################################################################### ## run ss-maintenance-enable ## # source /var/www/ss-maintenance-enable #################################################################################################### #### SS-Install-WordPress-Core: Cleanup Temporary Files ############################################ #################################################################################################### ## delete tmp files ## rm /tmp/wordpress* rm /tmp/throwaway* #################################################################################################### #### SS-Install-WordPress-Core: Install Ubuntu Utils ############################################### #################################################################################################### ## run ss-install-ubuntu-utils ## source /var/www/ss-install-ubuntu-utils #################################################################################################### #### SS-Install-WordPress-Core: Install WordPress Core (CMS) ####################################### #################################################################################################### ## CMS modules are installed on SlickStack via files hosted on our public mirror servers ## ## we always install the latest stable patched minor version (not major versions) ## ## cleanup files ## rm /var/www/html/wordpress* rm /var/www/html/staging/wordpress* rm /var/www/html/dev/wordpress* ## make dirs ## mkdir /var/www/html ## brief permissions reset ## chown -R $SFTP_USER:wordpress /var/www/html chown -R $SFTP_USER:wordpress /var/www/html/staging chown -R $SFTP_USER:wordpress /var/www/html/dev chmod 6775 /var/www/html chmod 6775 /var/www/html/staging chmod 6775 /var/www/html/dev ## download latest (patched) WordPress version ## wget -O /tmp/wordpress.zip http://mirrors.slickstack.io/wordpress/wordpress.zip #################################################################################################### #### SS-Install-WordPress-Core: Cleanup Files + Install WordPress Core (Production) ################ #################################################################################################### ## this installation process removes outdated WordPress Core files or potential malware ## ## it is not foolproof but it should address the majority of common problems ## ## cleanup old files and potential malware unless disabled ## if [[ -f "/tmp/wordpress.zip" ]] && [[ "$SS_INSTALL_WORDPRESS_CORE_DELETE_WP_ADMIN" != "false" ]]; then rm /var/www/html/wp-admin fi if [[ -f "/tmp/wordpress.zip" ]] && [[ "$SS_INSTALL_WORDPRESS_CORE_DELETE_WP_INCLUDES" != "false" ]]; then rm /var/www/html/wp-includes fi if [[ -f "/tmp/wordpress.zip" ]] && [[ "$SS_INSTALL_WORDPRESS_CORE_DELETE_PHP_FILES_ROOT" != "false" ]]; then find /var/www/html/ -maxdepth 1 -type f ! -name "wp-config.php" -name "*.php" -delete # cd /var/www/html/ && find . -type f ! -name "wp-config.php" -name "*.php" -delete fi ## copy zip to production ## cp /tmp/wordpress.zip /var/www/html unzip /var/www/html/wordpress.zip -d /var/www/html chown -R www-data:wordpress /var/www/html/wordpress chmod 775 /var/www/html/wordpress if [[ -f "/tmp/wordpress.zip" ]] && [[ "$SS_INSTALL_WORDPRESS_CORE_DELETE_BUNDLED_PLUGINS" != "false" ]]; then rm /var/www/html/wordpress/wp-content/plugins/akismet* rm /var/www/html/wordpress/wp-content/plugins/hello* fi if [[ -f "/tmp/wordpress.zip" ]] && [[ "$SS_INSTALL_WORDPRESS_CORE_DELETE_BUNDLED_THEMES" != "false" ]]; then rm /var/www/html/wordpress/wp-content/themes/twenty* fi ## install wp core files ## rsync /var/www/html/wordpress/* /var/www/html #################################################################################################### #### SS-Install-WordPress-Core: Cleanup Files + Install WordPress Core (Staging) ################### #################################################################################################### ## this installation process removes outdated WordPress Core files or potential malware ## ## it is not foolproof but it should address the majority of common problems ## ## cleanup old files and potential malware unless disabled ## if [[ -f "/tmp/wordpress.zip" ]] && [[ "$SS_INSTALL_WORDPRESS_CORE_DELETE_WP_ADMIN" != "false" ]]; then rm /var/www/html/staging/wp-admin fi if [[ -f "/tmp/wordpress.zip" ]] && [[ "$SS_INSTALL_WORDPRESS_CORE_DELETE_WP_INCLUDES" != "false" ]]; then rm /var/www/html/staging/wp-includes fi if [[ -f "/tmp/wordpress.zip" ]] && [[ "$SS_INSTALL_WORDPRESS_CORE_DELETE_PHP_FILES_ROOT" != "false" ]]; then find /var/www/html/staging/ -maxdepth 1 -type f ! -name "wp-config.php" -name "*.php" -delete # cd /var/www/html/staging/ && find . -type f ! -name "wp-config.php" -name "*.php" -delete fi ## copy zip to staging ## cp /tmp/wordpress.zip /var/www/html/staging unzip /var/www/html/staging/wordpress.zip -d /var/www/html/staging chown -R www-data:wordpress /var/www/html/staging/wordpress chmod 775 /var/www/html/staging/wordpress if [[ -f "/tmp/wordpress.zip" ]] && [[ "$SS_INSTALL_WORDPRESS_CORE_DELETE_BUNDLED_PLUGINS" != "false" ]]; then rm /var/www/html/staging/wordpress/wp-content/plugins/akismet* rm /var/www/html/staging/wordpress/wp-content/plugins/hello* fi if [[ -f "/tmp/wordpress.zip" ]] && [[ "$SS_INSTALL_WORDPRESS_CORE_DELETE_BUNDLED_THEMES" != "false" ]]; then rm /var/www/html/staging/wordpress/wp-content/themes/twenty* fi ## install wp core files ## rsync /var/www/html/staging/wordpress/* /var/www/html/staging #################################################################################################### #### SS-Install-WordPress-Core: Cleanup Files + Install WordPress Core (Dev) ####################### #################################################################################################### ## this installation process removes outdated WordPress Core files or potential malware ## ## it is not foolproof but it should address the majority of common problems ## ## cleanup old files and potential malware unless disabled ## if [[ -f "/tmp/wordpress.zip" ]] && [[ "$SS_INSTALL_WORDPRESS_CORE_DELETE_WP_ADMIN" != "false" ]]; then rm /var/www/html/dev/wp-admin fi if [[ -f "/tmp/wordpress.zip" ]] && [[ "$SS_INSTALL_WORDPRESS_CORE_DELETE_WP_INCLUDES" != "false" ]]; then rm /var/www/html/dev/wp-includes fi if [[ -f "/tmp/wordpress.zip" ]] && [[ "$SS_INSTALL_WORDPRESS_CORE_DELETE_PHP_FILES_ROOT" != "false" ]]; then find /var/www/html/dev/ -maxdepth 1 -type f ! -name "wp-config.php" -name "*.php" -delete # cd /var/www/html/dev/ && find . -type f ! -name "wp-config.php" -name "*.php" -delete fi ## copy zip to dev ## cp /tmp/wordpress.zip /var/www/html/dev unzip /var/www/html/dev/wordpress.zip -d /var/www/html/dev chown -R www-data:wordpress /var/www/html/dev/wordpress chmod 775 /var/www/html/dev/wordpress if [[ -f "/tmp/wordpress.zip" ]] && [[ "$SS_INSTALL_WORDPRESS_CORE_DELETE_BUNDLED_PLUGINS" != "false" ]]; then rm /var/www/html/dev/wordpress/wp-content/plugins/akismet* rm /var/www/html/dev/wordpress/wp-content/plugins/hello* fi if [[ -f "/tmp/wordpress.zip" ]] && [[ "$SS_INSTALL_WORDPRESS_CORE_DELETE_BUNDLED_THEMES" != "false" ]]; then rm /var/www/html/dev/wordpress/wp-content/themes/twenty* fi ## install wp core files ## rsync /var/www/html/dev/wordpress/* /var/www/html/dev #################################################################################################### #### SS-Install-WordPress-Core: More Cleanup ###################### #################################################################################################### ## cleanup files ## rm /tmp/wordpress.zip* &> /dev/null rm /var/www/html/wordpress* &> /dev/null rm /var/www/html/staging/wordpress* &> /dev/null rm /var/www/html/dev/wordpress* &> /dev/null #################################################################################################### #### SS-Install-WordPress-Core: Install Throwaway Theme (For Virgin Installs) ###################### #################################################################################################### ## a throwaway theme is an easy way to customize the cleanup routine for new installs ## ## there is no reason to install this for existing sites with live themes ## if [[ ! -f "/var/www/meta/.timestamp-ss-install-wordpress-core" ]]; then ## retrieve latest throwaway theme ## wget -O /tmp/throwaway.zip http://mirrors.slickstack.io/wordpress/throwaway.zip ## unzip ## unzip -d /tmp/throwaway/ -o -j /tmp/throwaway.zip ## replace placeholders with ss-config variables ## sed -i "s/@SITE_EMAIL/${SITE_EMAIL}/g" /tmp/throwaway/functions.php sed -i "s/@SITE_NAME/${SITE_NAME}/g" /tmp/throwaway/functions.php sed -i "s/@SITE_DOMAIN/${SITE_DOMAIN}/g" /tmp/throwaway/functions.php ## copy files to destinations ## cp /tmp/throwaway /var/www/html/wp-content/themes/ fi #################################################################################################### #### SS-Install-WordPress-Core: Fix Site Domains (Modify Database Options) ######################### #################################################################################################### ## SNIPPET: ss-install-wordpress-core, ss-install-wordpress-config ## here we manually fix certain fields in the MySQL database to ensure proper functions ## ## this fix required for WP Multisite (wp-config will override on single sites) ## ## fix site domains (production) ## 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'"; ## fix site domains (staging) ## if [[ "$STAGING_SITE" != "false" ]]; then mysql --execute="UPDATE ${DB_NAME}.staging_options SET option_value='https://$SITE_DOMAIN/staging' WHERE option_name='home'"; mysql --execute="UPDATE ${DB_NAME}.staging_options SET option_value='https://$SITE_DOMAIN/staging' WHERE option_name='siteurl'"; mysql --execute="UPDATE ${DB_NAME}_staging.${DB_PREFIX}options SET option_value='https://staging.$SITE_TLD' WHERE option_name='home'"; mysql --execute="UPDATE ${DB_NAME}_staging.${DB_PREFIX}options SET option_value='https://staging.$SITE_TLD' WHERE option_name='siteurl'"; fi ## fix site domains (dev) ## if [[ "$DEV_SITE" != "false" ]]; then mysql --execute="UPDATE ${DB_NAME}.dev_options SET option_value='https://$SITE_DOMAIN/dev' WHERE option_name='home'"; mysql --execute="UPDATE ${DB_NAME}.dev_options SET option_value='https://$SITE_DOMAIN/dev' WHERE option_name='siteurl'"; mysql --execute="UPDATE ${DB_NAME}_dev.${DB_PREFIX}options SET option_value='https://dev.$SITE_TLD' WHERE option_name='home'"; mysql --execute="UPDATE ${DB_NAME}_dev.${DB_PREFIX}options SET option_value='https://dev.$SITE_TLD' WHERE option_name='siteurl'"; fi #################################################################################################### #### SS-Install-WordPress-Core: Configure WP-Config File (Production + Staging) #################### #################################################################################################### ## this wp-config setup script is distinct so that it can be run separately if needed ## ## it will also be called whenever the ss-sync (staging sync) script is run ## ## UNCOMMENT AFTER STAGING AND DEV ARE WORKING ## ## run ss-install-wordpress-config ## # if [[ ! -f "/var/www/html/wp-config.php" ]] || [[ ! -f "/var/www/html/staging/wp-config.php" ]] || [[ ! -f "/var/www/html/dev/wp-config.php" ]]; then # source /var/www/ss-install-wordpress-config # fi #################################################################################################### #### SS-Install-WordPress-Core: Reset Permissions (WordPress Core) ################################# #################################################################################################### ## run ss-perms-wordpress-core ## source /var/www/ss-perms-wordpress-core #################################################################################################### #### SS-Install-WordPress-Core: Purge Cache (WordPress Transients) ################################# #################################################################################################### ## manually deletes all transients (temporary query cache data) from WordPress database ## ## this is a more forceful approach than simply purging the Redis object cache ## ## run ss-purge-transients ## source /var/www/ss-purge-transients #################################################################################################### #### SS-Install-WordPress-Core: Purge Cache (PHP OPcache) ########################################## #################################################################################################### ## run ss-purge-opcache ## source /var/www/ss-purge-opcache #################################################################################################### #### SS-Install-WordPress-Core: Purge Cache (Redis) ################################################ #################################################################################################### ## run ss-purge-redis ## source /var/www/ss-purge-redis #################################################################################################### #### SS-Install-WordPress-Core: Reset Permissions (WordPress Core) ################################# #################################################################################################### ## run ss-perms-wordpress-core ## source /var/www/ss-perms-wordpress-core #################################################################################################### #### SS-Install-WordPress-Core: Cleanup Temporary Files ############################################ #################################################################################################### ## delete tmp files ## rm /tmp/wordpress* rm /tmp/throwaway* #################################################################################################### #### SS-Install-WordPress-Core: Disable Maintenance Mode (Via SS-Maintenance-Disable) ############## #################################################################################################### ## run ss-maintenance-disable ## # source /var/www/ss-maintenance-disable #################################################################################################### #### SS-Install-WordPress-Core: Touch Timestamp File (End Script) ################################## #################################################################################################### ## 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 ## touch /var/www/meta/.timestamp-ss-install-wordpress-core #################################################################################################### #### SlickStack: External References Used To Improve This Script (Thanks, Interwebz) ############### #################################################################################################### ## Ref: https://github.com/littlebizzy/throwaway-theme/blob/master/functions.php ## SS_EOF