v-add-web-php 4.4 KB

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