add.inc 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #!/bin/bash
  2. hestia_module_php-fpm_add() {
  3. source $HESTIA/bin/module/func.inc
  4. source $HESTIA/bin/module/php/func.inc
  5. if ! hestia_module_isinstalled 'php-fpm' && [ ! "$param_force" ]; then
  6. echo "PHP (FPM) module is not installed. See 'hestia module info php-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 (FPM( 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-fpm.conf "php${php_withoutdot}_present" && echo 1)
  37. if [ "$php_version_present" ] && [ ! "$param_force" ]; then
  38. echo "PHP (FPM) version ${php_version} is already present. See 'hestia module php list'."
  39. return 0
  40. fi
  41. # Perform verification if read-only mode is enabled
  42. check_hestia_demo_mode
  43. echo "Adding PHP (FPM) version ${php_version}..."
  44. local php_prefix=$(osal_php_package_prefix $php_version)
  45. # Install php packages
  46. osal_package_preinstall
  47. osal_execute_with_spinner osal_package_install $php_prefix-fpm
  48. # Check if required modules for apache2 are enabled
  49. if [ "$WEB_SYSTEM" = "apache2" ] || [ "$WEB_SYSTEM" = "httpd" ]; then
  50. osal_apache_module_enable 'proxy_fcgi'
  51. osal_apache_module_enable 'setenvif'
  52. fi
  53. # Configure FPM
  54. osal_service_enable $php_prefix-fpm
  55. pool_d=$(osal_php_fpm_pool_d $php_version)
  56. if [ "$pool_d" ]; then
  57. mkdir -p $pool_d
  58. hestia_safe_rm $pool_d/*
  59. cp -f $HESTIA_INSTALL_DIR/php-fpm/dummy.conf $pool_d/
  60. sed -i "s/9999/99$php_withoutdot/g" $pool_d/dummy.conf # FIXME: this'll break with PHP 10.0
  61. fi
  62. # Install backend template
  63. cp -f $HESTIA_INSTALL_DIR/php-fpm/multiphp.tpl \
  64. $HESTIA/data/templates/web/php-fpm/PHP-${php_version/\./_}.tpl
  65. osal_kv_write $HESTIA_CONF_MODULES/php-fpm.conf "php${php_withoutdot}_present" '1'
  66. if hestia_module_isinstalled 'php'; then
  67. hestia module php add $php_version
  68. fi
  69. # Integrate everything
  70. if [ ! "$param_without_no_integrate" ]; then
  71. hestia module php-fpm integrate
  72. fi
  73. log_history "installed php $php_version" '' 'admin'
  74. }