v-add-web-php 3.9 KB

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