add.inc 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #!/bin/sh
  2. hestia_module_php_add() {
  3. source $HESTIA/bin/module/func.inc
  4. source $HESTIA/bin/module/php/func.inc
  5. module_installed=$(hestia_module_isinstalled php)
  6. if [ ! "$module_installed" ] && [ ! "$param_force" ]; then
  7. echo "PHP module is not installed. See 'hestia module info php'."
  8. exit 1
  9. fi
  10. module_variant=$(hestia_module_getvariant php)
  11. if [ "$module_variant" != 'php-fpm' ] && [ ! "$param_force" ]; then
  12. echo "The installed PHP module is not FPM. See 'hestia module info php'."
  13. exit 1
  14. fi
  15. if [ ! $param_ver ]; then
  16. echo "You must specify --ver [php_version]"
  17. exit 1
  18. fi
  19. # Verify php version format
  20. if [[ ! $param_ver =~ ^[0-9]\.[0-9]+ ]]; then
  21. echo "The PHP version format is invalid, it should look like [0-9].[0-9]."
  22. exit
  23. fi
  24. # Check version is supported
  25. php_version=''
  26. for ver in $PHP_SUPPORTED_VERSIONS; do
  27. if [ "$param_ver" == "$ver" ]; then
  28. php_version=$param_ver
  29. break;
  30. fi
  31. done
  32. if [ ! "$php_version" ]; then
  33. echo "PHP version $param_ver is not supported."
  34. exit 1
  35. fi
  36. php_withoutdot=${php_version//.}
  37. php_version_present=$(osal_kv_read_bool $HESTIA_CONF_MODULES/php.conf "php${php_withoutdot}_present")
  38. if [ "$php_version_present" ] && [ ! "$param_force" ]; then
  39. echo "PHP version ${php_version} is already present. See 'hestia module php list'."
  40. exit 1
  41. fi
  42. # Check if php version is supported
  43. if [ ! -f "$HESTIA_INSTALL_DIR/multiphp/$WEB_SYSTEM/PHP-${php_withoutdot}.sh" ]; then
  44. echo "PHP version ${php_version} is currently not supported or does not exist."
  45. exit
  46. fi
  47. # Perform verification if read-only mode is enabled
  48. check_hestia_demo_mode
  49. echo "Adding PHP version ${php_version}..."
  50. php_prefix=$(osal_multiphp_php_package_prefix $php_version)
  51. mph="$php_prefix-mbstring $php_prefix-bcmath $php_prefix-cli $php_prefix-curl
  52. $php_prefix-fpm $php_prefix-gd $php_prefix-intl $php_prefix-mysql
  53. $php_prefix-soap $php_prefix-xml $php_prefix-zip $php_prefix-mbstring
  54. $php_prefix-json $php_prefix-bz2 $php_prefix-pspell $php_prefix-imagick $php_prefix-pgsql
  55. $php_prefix-imap $php_prefix-ldap"
  56. # Check is version is 7.1 or below to add mcrypt
  57. if [[ `echo "$php_version 7.2" | awk '{print ($1 < $2)}'` == 1 ]]; then
  58. mph="$mph $php_prefix-mcrypt"
  59. fi
  60. # Install php packages
  61. osal_package_preinstall
  62. osal_execute_with_spinner osal_package_install $mph
  63. # Check if installation was sucessfully
  64. if [ ! $(osal_multiphp_fpm_isinstalled $php_version) ]; then
  65. echo "Installation failed, please run the following command manualy for debuging:"
  66. echo "$OSAL_CMD_PACKAGE_MANAGER install ${mph//\\n/ \\}"
  67. fi
  68. # Check if required modules for apache2 are enabled
  69. if [ "$WEB_SYSTEM" = "apache2" ] || [ "$WEB_SYSTEM" = "httpd" ]; then
  70. osal_apache_module_enable 'proxy_fcgi'
  71. osal_apache_module_enable 'setenvif'
  72. $BIN/v-restart-web
  73. fi
  74. # Configure fpm
  75. osal_service_enable $php_prefix-fpm > /dev/null 2>&1
  76. pool_d=$(osal_multiphp_fpm_pool_d $php_version)
  77. if [ $pool_d ]; then
  78. rm -f $pool_d/*
  79. cp -f $HESTIA_INSTALL_DIR/php-fpm/dummy.conf $pool_d/
  80. sed -i "s/9999/99$php_withoutdot/g" $pool_d/dummy.conf # FIXME: this'll break with PHP 10.0
  81. fi
  82. # Install backend template
  83. cp -f $HESTIA_INSTALL_DIR/php-fpm/multiphp.tpl \
  84. $HESTIA/data/templates/web/php-fpm/PHP-${php_version/\./_}.tpl
  85. #----------------------------------------------------------#
  86. # Hestia #
  87. #----------------------------------------------------------#
  88. osal_kv_write $HESTIA_CONF_MODULES/php.conf "php${php_withoutdot}_present" '1'
  89. log_history "installed php $php_version" '' 'admin'
  90. exit 0
  91. }