v-add-web-php 3.8 KB

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