install.inc 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/bin/bash
  2. hestia_module_apache_install() {
  3. source $HESTIA/bin/module/func.inc
  4. if hestia_module_isinstalled 'apache' && [ ! "$param_force" ]; then
  5. echo "Apache module is already installed. See 'hestia module info apache'."
  6. return 0
  7. fi
  8. echo "Installing Apache module..."
  9. osal_service_stop $OSAL_SERVICE_APACHE > /dev/null 2>&1
  10. hestia_config_backup 'apache-install' $OSAL_PATH_APACHE_CONF $OSAL_PATH_APACHE_CONF_D
  11. # Setup repos
  12. if [ "$OS_BASE" = 'debian' ]; then
  13. cat > /etc/apt/sources.list.d/apache2.list <<EOL
  14. # This file was added by Hestia Control Panel.
  15. deb https://packages.sury.org/apache2/ $OS_CODENAME main
  16. EOL
  17. apt-key adv --fetch-keys 'https://packages.sury.org/apache2/apt.gpg' > /dev/null 2>&1
  18. elif [ "$OS_BASE" = 'ubuntu' ]; then
  19. cat > /etc/apt/sources.list.d/apache2.list <<EOL
  20. # This file was added by Hestia Control Panel.
  21. deb http://ppa.launchpad.net/ondrej/apache2/ubuntu $OS_CODENAME main
  22. EOL
  23. fi
  24. osal_package_preinstall
  25. osal_package_install $OSAL_PKG_APACHE $OSAL_PKG_APACHE_EXTRA
  26. mkdir -p $OSAL_PATH_APACHE_CONF_D/domains
  27. # Enable/disable required modules
  28. osal_apache_module_enable rewrite > /dev/null 2>&1
  29. osal_apache_module_enable suexec > /dev/null 2>&1
  30. osal_apache_module_enable ssl > /dev/null 2>&1
  31. osal_apache_module_enable actions > /dev/null 2>&1
  32. osal_apache_module_disable status > /dev/null 2>&1
  33. cp -f $HESTIA_INSTALL_DIR/$OSAL_PKG_APACHE/${OSAL_PKG_APACHE}.conf $OSAL_PATH_APACHE_CONF/
  34. cp -f $HESTIA_INSTALL_DIR/logrotate/${OSAL_PKG_APACHE} $OSAL_PATH_LOGROTATE_CONF_D/
  35. echo "# Powered by Hestia" > $OSAL_PATH_APACHE_CONF/ports.conf
  36. if [ "$OS_BASE" = 'debian' ]; then
  37. echo "# Powered by Hestia" > $OSAL_PATH_APACHE_CONF/sites-available/default
  38. echo "# Powered by Hestia" > $OSAL_PATH_APACHE_CONF/sites-available/default-ssl
  39. echo -e "/home\npublic_html/cgi-bin" > /etc/apache2/suexec/www-data
  40. hestia_safe_rm $OSAL_PATH_APACHE_CONF/mods-available/hestia-status.load
  41. hestia_safe_rm $OSAL_PATH_APACHE_CONF/mods-available/hestia-status.conf
  42. # Copy configuration files
  43. cp -f $HESTIA_INSTALL_DIR/$OSAL_PKG_APACHE/status.conf $OSAL_PATH_APACHE_MODS_AVAILABLE/
  44. cp -f /etc/apache2/mods-available/status.load $OSAL_PATH_APACHE_MODS_AVAILABLE/
  45. # Prevent remote access to server-status page
  46. sed -i '/Allow from all/d' $OSAL_PATH_APACHE_MODS_AVAILABLE/status.conf
  47. osal_apache_module_enable status > /dev/null 2>&1
  48. elif [ "$OS_BASE" = 'rhel' ]; then
  49. echo "# Powered by Hestia" > $OSAL_PATH_APACHE_CONF_D/ssl.conf
  50. echo "# Powered by Hestia" > $OSAL_PATH_APACHE_CONF_D/welcome.conf
  51. echo "# Powered by Hestia" > $OSAL_PATH_APACHE_CONF_D/userdir.conf
  52. # Copy configuration files
  53. cp -f $HESTIA_INSTALL_DIR/$OSAL_PKG_APACHE/status.conf $OSAL_PATH_APACHE_CONF_D/
  54. # Prevent remote access to server-status page
  55. sed -i '/Allow from all/d' $OSAL_PATH_APACHE_CONF_D/status.conf
  56. osal_apache_module_enable status > /dev/null 2>&1
  57. # Delete CentOS style apache logs if present (Hestia will use error.log and access.log)
  58. [ -f /var/log/$OSAL_PKG_APACHE/access_log ] && hestia_safe_rm /var/log/$OSAL_PKG_APACHE/access_log
  59. [ -f /var/log/$OSAL_PKG_APACHE/error_log ] && hestia_safe_rm /var/log/$OSAL_PKG_APACHE/error_log
  60. # Mitigation for some Debian-only scripts
  61. [ ! -e /etc/httpd/mods-enabled ] && ln -s /etc/httpd/conf.modules.d/ /etc/httpd/mods-enabled
  62. fi
  63. touch /var/log/$OSAL_PKG_APACHE/access.log /var/log/$OSAL_PKG_APACHE/error.log
  64. mkdir -p /var/log/$OSAL_PKG_APACHE/domains
  65. chmod a+x /var/log/$OSAL_PKG_APACHE
  66. chmod 640 /var/log/$OSAL_PKG_APACHE/access.log /var/log/$OSAL_PKG_APACHE/error.log
  67. chmod 751 /var/log/$OSAL_PKG_APACHE/domains
  68. osal_kv_write $HESTIA_CONF_MODULES/apache.conf 'service_name' $OSAL_SERVICE_APACHE
  69. }