v-add-web-php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #!/bin/bash
  2. # info: add php fpm version
  3. # options: VERSION
  4. #
  5. # example: v-add-web-php 8.0
  6. #
  7. # This function checks and delete a fpm php version if not used by any domain.
  8. #----------------------------------------------------------#
  9. # Variables & Functions #
  10. #----------------------------------------------------------#
  11. # Argument definition
  12. version=$1
  13. # Includes
  14. # shellcheck source=/etc/hestiacp/hestia.conf
  15. source /etc/hestiacp/hestia.conf
  16. # shellcheck source=/usr/local/hestia/func/main.sh
  17. source $HESTIA/func/main.sh
  18. # load config file
  19. source_conf "$HESTIA/conf/hestia.conf"
  20. #----------------------------------------------------------#
  21. # Verifications #
  22. #----------------------------------------------------------#
  23. check_args '1' "$#" 'VERSION'
  24. # Set file locations
  25. php_fpm="/etc/init.d/php$version-fpm"
  26. # Verify php version format
  27. if [[ ! $version =~ ^[0-9]\.[0-9]+ ]]; then
  28. echo "The specified PHP version format is invalid, it should look like [0-9].[0-9]."
  29. echo "Example: 7.0, 7.4, 8.0"
  30. exit "$E_INVALID";
  31. fi
  32. # Check if php version already exists
  33. if [ -f "$php_fpm" ] && [ -f "$HESTIA/data/templates/web/php-fpm/PHP-${version/\./_}.tpl" ]; then
  34. echo "ERROR: Specified PHP version is already installed."
  35. exit "$E_INVALID";
  36. fi
  37. # Check if php version is supported
  38. if [ ! -f "$HESTIA_INSTALL_DIR/multiphp/$WEB_SYSTEM/PHP-${version//.}.sh" ]; then
  39. echo "ERROR: Specified PHP version is not supported or does not exist."
  40. exit "$E_INVALID";
  41. fi
  42. # Perform verification if read-only mode is enabled
  43. check_hestia_demo_mode
  44. #----------------------------------------------------------#
  45. # Action #
  46. #----------------------------------------------------------#
  47. mph="php$version-common php$version-mbstring php$version-bcmath php$version-cli php$version-curl
  48. php$version-fpm php$version-gd php$version-intl php$version-mysql
  49. php$version-soap php$version-xml php$version-zip php$version-json php$version-bz2
  50. php$version-pspell php$version-imagick php$version-pgsql php$version-imap php$version-ldap"
  51. # Check is version is 7.1 or below to add mcrypt
  52. if [[ `echo "$version 7.2" | awk '{print ($1 < $2)}'` == 1 ]]; then
  53. mph="$mph php$version-mcrypt"
  54. fi
  55. # Check if version is 8.0 or higher and drop php json.
  56. if [[ ${version:0:1} == "8" ]]; then
  57. mph=$(echo "$mph" | sed -e "s/php$version-json//")
  58. fi
  59. if ! echo "$DB_SYSTEM" | grep -w 'mysql' >/dev/null; then
  60. mph=$(echo "$mph" | sed -e "s/php$version-mysql//")
  61. fi
  62. if ! echo "$DB_SYSTEM" | grep -w 'pgsql' >/dev/null; then
  63. mph=$(echo "$mph" | sed -e "s/php$version-pgsql//")
  64. fi
  65. # Install php packages
  66. apt-get -qq update
  67. apt-get -y -qq -o Dpkg::Options::="--force-confold" install $mph > /dev/null 2>&1 &
  68. BACK_PID=$!
  69. # Check if package installation is done, print a spinner
  70. echo "Installing PHP-$version, please wait..."
  71. spinner="/-\|"
  72. spin_i=1
  73. while kill -0 $BACK_PID > /dev/null 2>&1 ; do
  74. printf "\b${spinner:spin_i++%${#spinner}:1}"
  75. sleep 0.5
  76. done
  77. # Do a blank echo to get the \n back
  78. echo
  79. # Check if installation was successful
  80. if [ ! -f "$php_fpm" ]; then
  81. echo "ERROR: Installation failed, please run the following command manually for debugging:"
  82. echo "apt-get install $mph"
  83. fi
  84. # Check if required modules for apache2 are enabled
  85. if [ "$WEB_SYSTEM" = "apache2" ]; then
  86. if ! a2query -q -m proxy_fcgi; then
  87. a2enmod -q proxy_fcgi
  88. fi
  89. if ! a2query -q -m setenvif; then
  90. a2enmod -q setenvif
  91. fi
  92. $BIN/v-restart-web "yes"
  93. fi
  94. # Configure fpm
  95. update-rc.d php$version-fpm defaults > /dev/null 2>&1
  96. v_tpl=${version//.}
  97. rm -f /etc/php/$version/fpm/pool.d/*
  98. cp -f $HESTIA_INSTALL_DIR/php-fpm/dummy.conf /etc/php/$version/fpm/pool.d/
  99. sed -i "s/9999/99$v_tpl/g" /etc/php/$version/fpm/pool.d/dummy.conf
  100. cp -f $HESTIA_INSTALL_DIR/php-fpm/php-fpm.conf /etc/php/$version/fpm/
  101. sed -i "s/fpm_v/$version/g" /etc/php/$version/fpm/php-fpm.conf
  102. # Install backend template
  103. cp -f $HESTIA_INSTALL_DIR/php-fpm/multiphp.tpl \
  104. $HESTIA/data/templates/web/php-fpm/PHP-${version/\./_}.tpl
  105. #----------------------------------------------------------#
  106. # Hestia #
  107. #----------------------------------------------------------#
  108. # Logging
  109. $BIN/v-log-action "system" "Info" "System" "Installed PHP $version."
  110. log_event "$OK" "$ARGUMENTS"
  111. exit