add.inc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #!/bin/bash
  2. hestia_module_php_add() {
  3. source $HESTIA/bin/module/func.inc
  4. source $HESTIA/bin/module/php/func.inc
  5. if ! hestia_module_isinstalled 'php' && [ ! "$param_force" ]; then
  6. echo "PHP module is not installed. See 'hestia module info php'."
  7. return 1
  8. fi
  9. # PHP version is first parameter
  10. param_ver="$1"
  11. if [ ! "$param_ver" ]; then
  12. echo "You must specify PHP version"
  13. return 1
  14. fi
  15. if [ "$param_ver" == "default" ]; then
  16. param_ver="$PHP_DEFAULT_VERSION"
  17. fi
  18. # Verify php version format
  19. if [[ ! "$param_ver" =~ ^[0-9]\.[0-9]+ ]]; then
  20. echo "The PHP version format is invalid, it should look like [0-9].[0-9]."
  21. exit
  22. fi
  23. # Check version is supported
  24. php_version=''
  25. for ver in $PHP_SUPPORTED_VERSIONS; do
  26. if [ "$param_ver" == "$ver" ]; then
  27. php_version="$param_ver"
  28. break;
  29. fi
  30. done
  31. if [ ! "$php_version" ]; then
  32. echo "PHP version $param_ver is not supported."
  33. return 1
  34. fi
  35. local php_withoutdot=${php_version//.}
  36. local php_version_present=$(osal_kv_read_bool $HESTIA_CONF_MODULES/php.conf "php${php_withoutdot}_present" && echo 1)
  37. if [ "$php_version_present" ] && [ ! "$param_force" ]; then
  38. echo "PHP version ${php_version} is already present. See 'hestia module php list'."
  39. return 0
  40. fi
  41. # Check if php version is supported
  42. # TODO:
  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. return 1
  46. fi
  47. # Perform verification if read-only mode is enabled
  48. check_hestia_demo_mode
  49. echo "Adding PHP version ${php_version}..."
  50. local php_prefix=$(osal_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_php_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. fi
  73. # Configure FPM
  74. osal_service_enable $php_prefix-fpm
  75. pool_d=$(osal_php_fpm_pool_d $php_version)
  76. if [ "$pool_d" ]; then
  77. mkdir -p $pool_d
  78. hestia_safe_rm $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. hestia module php integrate
  91. }