#!/bin/bash #################################################################################################### #### author: SlickStack ############################################################################ #### link: https://slickstack.io ################################################################### #### mirror: http://mirrors.slickstack.io/bash/ss-install-php-core.txt ############################# #### path: /var/www/ss-install-php-core ############################################################ #### destination: n/a (not a boilerplate) ########################################################## #### purpose: Reinstalls the PHP-FPM module Ubuntu packages and extensions (idempotent) ############ #### module version: PHP-FPM 7.4.x ################################################################# #### sourced by: ss-install-php #################################################################### #### bash aliases: ss install php 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-PHP-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-php-core: Reinstalls the PHP-FPM module Ubuntu packages and extensions (idempotent)... ${NOCOLOR}" sleep "$SLEEP_MESSAGE_BEGIN" #################################################################################################### #### SS-Install-PHP: Purge Any Existing PHP Packages (Ubuntu) ###################################### #################################################################################################### ## here we first purge any existing PHP packages and then reinstall PHP-FPM from scratch ## ## this approach is safe and helps avoid any conflicts between package versions ## ## purge packages ## apt purge ^php ## delete any leftover PHP files (disable for now because apt will not create these files if it notices the php directory exists already) ## # rm /etc/php* ## cleanup any outdated packages and system files ## apt autoremove apt autoclean ## update repo cache ## apt update #################################################################################################### #### SS-Install-PHP: Install PHP-FPM + PHP Extensions (Ubuntu Packages) ############################ #################################################################################################### ## here PHP-FPM will be installed along with any custom PHP extensions in your ss-config ## ## remember to check version compatibility of PHP extensions if you modify them ## ## install php-fpm (php7.x not needed for php7.x-fpm) ## if [[ "${UBUNTU_VERSION}" = "20.04" ]] && [[ -n "$PHP_EXTENSIONS" ]]; then PHP_EXTENSIONS_NOW=$(source /var/www/ss-config; echo $PHP_EXTENSIONS) apt install $PHP_EXTENSIONS_NOW else apt install php7.4-fpm php7.4-bcmath php7.4-curl php7.4-gd php7.4-imagick php7.4-json php7.4-mbstring php7.4-mysql php7.4-soap php7.4-xml php7.4-zip fi if [[ "${UBUNTU_VERSION}" = "18.04" ]]; then apt install php7.2-fpm php7.2-bcmath php7.2-curl php7.2-gd php7.2-imagick php7.2-json php7.2-mbstring php7.2-mysql php7.2-soap php7.2-xml php7.2-zip fi ## install php-redis (required) ## if [[ "${UBUNTU_VERSION}" = "20.04" ]]; then apt install php-redis fi if [[ "${UBUNTU_VERSION}" = "18.04" ]]; then apt install php-redis fi #################################################################################################### #### SS-Install-PHP-Core: Set Default PHP Version In Ubuntu ######################################## #################################################################################################### ## here we set the default PHP version depending on the version of Ubuntu LTS detected ## ## in most cases this step is not necessary but we do it anyway for consistency ## ## php 7.4 default (Ubuntu 20.04 LTS) ## if [[ "${UBUNTU_VERSION}" = "20.04" ]]; then update-alternatives --set php /usr/bin/php7.4 fi ## php 7.2 default (Ubuntu 18.04 LTS) ## if [[ "${UBUNTU_VERSION}" = "18.04" ]]; then update-alternatives --set php /usr/bin/php7.2 fi #################################################################################################### #### SS-Install-PHP-Core: Reset Permissions (PHP-FPM) ############################################## #################################################################################################### ## run ss-perms-php ## source /var/www/ss-perms-php #################################################################################################### #### SS-Install-PHP-Core: Purge Cache (PHP OPcache) ################################################ #################################################################################################### ## run ss-purge-opcache ## source /var/www/ss-purge-opcache #################################################################################################### #### SS-Install-PHP-Core: Restart Services (PHP-FPM) ############################################### #################################################################################################### ## restart services ## /etc/init.d/php*-fpm restart #################################################################################################### #### SS-Install-PHP-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-php-core #################################################################################################### #### SlickStack: External References Used To Improve This Script (Thanks, Interwebz) ############### #################################################################################################### ## Ref: https://askubuntu.com/questions/541781/install-list-of-packages-using-apt-get ## Ref: https://stackoverflow.com/questions/22284131/why-cant-i-install-multiple-packages-with-apt-get-install ## Ref: https://askubuntu.com/questions/913221/why-does-my-install-shell-script-not-work-when-i-can-run-it-line-by-line-and-it ## Ref: https://askubuntu.com/questions/39497/apt-get-install-multiple-packages-without-stopping ## SS_EOF