v-add-web-php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #!/bin/bash
  2. # info: add php fpm version
  3. # options: VERSION
  4. # labels: hestia
  5. #
  6. # example: v-add-web-php 8.0
  7. #
  8. # The function checks and delete a fpm php version if not used by any domain.
  9. #----------------------------------------------------------#
  10. # Variable&Function #
  11. #----------------------------------------------------------#
  12. # Argument definition
  13. version=$1
  14. # Includes
  15. # shellcheck source=/usr/local/hestia/func/main.sh
  16. source $HESTIA/func/main.sh
  17. # shellcheck source=/usr/local/hestia/conf/hestia.conf
  18. source $HESTIA/conf/hestia.conf
  19. #----------------------------------------------------------#
  20. # Verifications #
  21. #----------------------------------------------------------#
  22. check_args '1' "$#" 'VERSION'
  23. # Set file locations
  24. php_fpm="/etc/init.d/php$version-fpm"
  25. # Verify php version format
  26. if [[ ! $version =~ ^[0-9]\.[0-9]+ ]]; then
  27. echo "The specified PHP version format is invalid, it should look like [0-9].[0-9]."
  28. echo "Example: 7.0, 7.4, 8.0"
  29. exit
  30. fi
  31. # Check if php version already exists
  32. if [ -f "$php_fpm" ] && [ -f "$HESTIA/data/templates/web/php-fpm/PHP-${version/\./_}.tpl" ]; then
  33. echo "ERROR: Specified PHP version is already installed."
  34. exit
  35. fi
  36. # Check if php version is supported
  37. if [ ! -f "$HESTIA_INSTALL_DIR/multiphp/$WEB_SYSTEM/PHP-${version//.}.sh" ]; then
  38. echo "ERROR: Specified PHP version is not supported or does not exist."
  39. exit
  40. fi
  41. # Perform verification if read-only mode is enabled
  42. check_hestia_demo_mode
  43. #----------------------------------------------------------#
  44. # Action #
  45. #----------------------------------------------------------#
  46. mph="php$version-mbstring php$version-bcmath php$version-cli php$version-curl
  47. php$version-fpm php$version-gd php$version-intl php$version-mysql
  48. php$version-soap php$version-xml php$version-zip php$version-mbstring
  49. php$version-json php$version-bz2 php$version-pspell php$version-imagick php$version-pgsql
  50. 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 sucessfully
  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
  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. # Install backend template
  101. cp -f $HESTIA_INSTALL_DIR/php-fpm/multiphp.tpl \
  102. $HESTIA/data/templates/web/php-fpm/PHP-${version/\./_}.tpl
  103. #----------------------------------------------------------#
  104. # Hestia #
  105. #----------------------------------------------------------#
  106. # Logging
  107. $BIN/v-log-action "system" "Info" "System" "Installed PHP $version."
  108. log_event "$OK" "$ARGUMENTS"
  109. exit