#!/bin/bash #################################################################################################### #### author: SlickStack ############################################################################ #### link: https://slickstack.io ################################################################### #### mirror: https://mirrors.slickstack.io/bash/ss-restart-php.txt ################################# #### path: /var/www/ss-restart-php ################################################################# #### destination: n/a (not a boilerplate) ########################################################## #### purpose: Forcefully restarts the PHP-FPM service by using init.d absolute path ################ #### module version: PHP-FPM 8.1.x ################################################################# #### bash aliases: ss restart php, ss restart php-fpm ############################################## #################################################################################################### ## YOU CAN RUN SS-RESTART FOR AN EASY WAY TO RESTART ALL CORE SLICKSTACK (LEMP) MODULES ## ## THIS DOES NOT INCLUDE ANY CUSTOM UBUNTU PACKAGES THAT YOU MAY HAVE INSTALLED ## ## 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-Restart-PHP) ############################################################ #################################################################################################### ## 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. Forcefully Restart PHP-FPM #################################################################################################### #### A. SS-Restart-PHP: 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 ## ss_touch "${TIMESTAMP_SS_RESTART_PHP}" #################################################################################################### #### B. SS-Restart-PHP: Message (Begin Script) ##################################################### #################################################################################################### ## this is a simple message that announces to the shell the purpose of this bash script ## ## it will only be seen by sudo users who manually run this script in the shell ## ss_echo "${COLOR_INFO}Running ss-restart-php... ${COLOR_RESET}" #################################################################################################### #### C. SS-Restart-PHP: Forcefully Restart PHP-FPM ################################################# #################################################################################################### ## this snippet uses init.d instead of systemd shortcuts to allow for absolute paths ## ## the given service will be forcefully restarted and output sent to /dev/null ## if [[ "${SS_APP}" != "mysql" ]]; then ## cancel this one ## ## restart php-fpm service ## ## ss_restart php*-fpm ## reload more graceful than restart for production ## https://www.cyberciti.biz/faq/how-to-reload-restart-php7-0-fpm-service-linux-unix/ ## alt example (swap into ss_restart function later): systemctl restart php8.1-fpm.service ss_reload php*-fpm fi #################################################################################################### #### SlickStack: 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://unix.stackexchange.com/questions/370942/do-you-need-to-reload-after-adding-a-rule-in-ufw/370947 ## Ref: http://blog.jonathanargentiero.com/failed-to-restart-mysql-service-unit-mysql-service-is-masked/ ## Ref: https://support.plesk.com/hc/en-us/articles/360021187734-The-service-fails-to-start-on-a-Linux-server-service-is-masked ## Ref: https://jira.percona.com/browse/PS-5226 ## Ref: https://blog.ruanbekker.com/blog/2017/12/09/unmask-a-masked-service-in-systemd/ ## Ref: https://askubuntu.com/questions/992464/version-agnostic-php-fpm-restart ## Ref: https://serverfault.com/questions/189940/how-do-you-restart-php-fpm ## Ref: https://stackoverflow.com/questions/41319291/ufw-blocks-most-ports-until-disabled-and-re-enabled-after-reboot ## Ref: https://www.vultr.com/docs/configure-ubuntu-firewall-ufw-on-ubuntu-18-04 ## Ref: https://askubuntu.com/questions/2075/whats-the-difference-between-service-and-etc-init-d ## Ref: https://www.digitalocean.com/community/tutorials/how-to-use-systemctl-to-manage-systemd-services-and-units ## Ref: https://stackoverflow.com/questions/10193788/restarting-cron-after-changing-crontab-file ## Ref: https://discourse.roots.io/t/is-the-restart-of-php-fpm-on-each-deploy-necessary/21672 ## Ref: https://laracasts.com/discuss/channels/forge/restarting-php-fpm-in-deploy-script ## Ref: https://www.datadoghq.com/blog/nginx-502-bad-gateway-errors-php-fpm/ ## Ref: https://medium.com/@richb_/tweaking-nginx-and-php-fpm-configuration-to-fix-502-bad-gateway-errors-and-optimise-performance-on-17465f41fd87 ## Ref: https://stackoverflow.com/questions/37318795/why-does-envoyer-need-to-restart-php-fpm-when-deploying ## Ref: https://stackoverflow.com/questions/14915147/php-fpm-check-if-running ## SS_EOF