v-add-web-php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 php version format is invalid, it should look like [0-9].[0-9]..."
  23. exit
  24. fi
  25. # Check if php version already exists
  26. if [ -f "$php_fpm" ] && [ -f "$HESTIA/data/templates/web/php-fpm/PHP-${version/\./_}.tpl" ]; then
  27. echo "Version already installed..."
  28. exit
  29. fi
  30. # Check if php version is supported
  31. if [ ! -f "$HESTIA_INSTALL_DIR/multiphp/$WEB_SYSTEM/PHP-${version//.}.sh" ]; then
  32. echo "Version is currently not supported or does not exist..."
  33. exit
  34. fi
  35. # Perform verification if read-only mode is enabled
  36. check_hestia_demo_mode
  37. #----------------------------------------------------------#
  38. # Action #
  39. #----------------------------------------------------------#
  40. mph="php$version-mbstring php$version-bcmath php$version-cli php$version-curl
  41. php$version-fpm php$version-gd php$version-intl php$version-mysql
  42. php$version-soap php$version-xml php$version-zip php$version-mbstring
  43. php$version-json php$version-bz2 php$version-pspell php$version-imagick php$version-pgsql"
  44. # Check is version is 7.1 or below to add mcrypt
  45. if [[ `echo "$version 7.2" | awk '{print ($1 < $2)}'` == 1 ]]; then
  46. mph="$mph php$version-mcrypt"
  47. fi
  48. if [ -z "$DB_SYSTEM" -o "$DB_SYSTEM" = "mysql" ]; then
  49. mph=$(echo "$mph" | sed -e "s/php$version-pgsql//")
  50. fi
  51. if [ -z "$DB_SYSTEM" -o "$DB_SYSTEM" = "pgsql" ]; then
  52. mph=$(echo "$mph" | sed -e "s/php$version-mysql//")
  53. fi
  54. # Install php packages
  55. apt-get -qq update
  56. apt-get -y -qq -o Dpkg::Options::="--force-confold" install $mph > /dev/null 2>&1 &
  57. BACK_PID=$!
  58. # Check if package installation is done, print a spinner
  59. echo "Install PHP-$version, please wait..."
  60. spinner="/-\|"
  61. spin_i=1
  62. while kill -0 $BACK_PID > /dev/null 2>&1 ; do
  63. printf "\b${spinner:spin_i++%${#spinner}:1}"
  64. sleep 0.5
  65. done
  66. # Do a blank echo to get the \n back
  67. echo
  68. # Check if installation was sucessfully
  69. if [ ! -f "$php_fpm" ]; then
  70. echo "Installation failed, please run the following command manualy for debuging:"
  71. echo "apt-get install $mph"
  72. fi
  73. # Check if required modules for apache2 are enabled
  74. if [ "$WEB_SYSTEM" = "apache2" ]; then
  75. if ! a2query -q -m proxy_fcgi; then
  76. a2enmod -q proxy_fcgi
  77. fi
  78. if ! a2query -q -m setenvif; then
  79. a2enmod -q setenvif
  80. fi
  81. $BIN/v-restart-web
  82. fi
  83. # Configure fpm
  84. update-rc.d php$version-fpm defaults > /dev/null 2>&1
  85. v_tpl=${version//.}
  86. rm -f /etc/php/$version/fpm/pool.d/*
  87. cp -f $HESTIA_INSTALL_DIR/php-fpm/dummy.conf /etc/php/$version/fpm/pool.d/
  88. sed -i "s/9999/99$v_tpl/g" /etc/php/$version/fpm/pool.d/dummy.conf
  89. # Install backend template
  90. cp -f $HESTIA_INSTALL_DIR/php-fpm/multiphp.tpl \
  91. $HESTIA/data/templates/web/php-fpm/PHP-${version/\./_}.tpl
  92. #----------------------------------------------------------#
  93. # Hestia #
  94. #----------------------------------------------------------#
  95. # Logging
  96. log_history "installed php $version" '' 'admin'
  97. log_event "$OK" "$ARGUMENTS"
  98. exit