v-change-sys-php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/bin/bash
  2. # info: Change default php version server wide
  3. # options: VERSION
  4. #
  5. # example: v-change-sys-php 8.0
  6. #
  7. # Changes default PHP version server width usd by the "Default" template and Webmail
  8. version=$1
  9. # Includes
  10. # shellcheck source=/etc/hestiacp/hestia.conf
  11. source /etc/hestiacp/hestia.conf
  12. # shellcheck source=/usr/local/hestia/func/main.sh
  13. source $HESTIA/func/main.sh
  14. # load config file
  15. source_conf "$HESTIA/conf/hestia.conf"
  16. #----------------------------------------------------------#
  17. # Variables & Functions #
  18. #----------------------------------------------------------#
  19. check_args '1' "$#" 'VERSION'
  20. # Verify php version format
  21. if [[ ! $version =~ ^[0-9]\.[0-9]+ ]]; then
  22. echo "The specified PHP version format is invalid, it should look like [0-9].[0-9]."
  23. echo "Example: 7.0, 7.4, 8.0"
  24. exit "$E_INVALID"
  25. fi
  26. # Check if php version exists
  27. version_check=$($BIN/v-list-sys-php plain | grep "$version")
  28. if [ -z "$version_check" ]; then
  29. echo "ERROR: Specified PHP version is not installed."
  30. exit "$E_INVALID"
  31. fi
  32. # Perform verification if read-only mode is enabled
  33. check_hestia_demo_mode
  34. #----------------------------------------------------------#
  35. # Action #
  36. #----------------------------------------------------------#
  37. # Set file locations
  38. php_fpm="/etc/init.d/php$version-fpm"
  39. rm -f /etc/php/*/fpm/pool.d/www.conf
  40. cp -f $HESTIA/install/deb/php-fpm/www.conf /etc/php/$version/fpm/pool.d/www.conf
  41. for user in $("$BIN/v-list-users" list); do
  42. $BIN/v-rebuild-web-domains "$user" 'no' > /dev/null 2>&1
  43. $BIN/v-rebuild-mail-domains "$user" 'no' > /dev/null 2>&1
  44. done
  45. # Reload "current" php version before reload everthing
  46. $BIN/v-restart-web-backend '' $(multiphp_default_version)
  47. $BIN/v-restart-web-backend
  48. $BIN/v-restart-web
  49. $BIN/v-restart-proxy
  50. update-alternatives --set php /usr/bin/php$version
  51. #----------------------------------------------------------#
  52. # Hestia #
  53. #----------------------------------------------------------#
  54. log_event "$OK" "$ARGUMENTS"