v-change-sys-php 2.0 KB

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