install.inc 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. echo > $OSAL_PATH_APACHE_CONF_D/dir.conf <<EOL # This file was added by Hestia Control Panel.
  53. <IfModule mod_dir.c>
  54. DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
  55. </IfModule>
  56. EOL
  57. # Copy configuration files
  58. cp -f $HESTIA_INSTALL_DIR/$OSAL_PKG_APACHE/status.conf $OSAL_PATH_APACHE_CONF_D/
  59. # Prevent remote access to server-status page
  60. sed -i '/Allow from all/d' $OSAL_PATH_APACHE_CONF_D/status.conf
  61. osal_apache_module_enable status > /dev/null 2>&1
  62. # Delete CentOS style apache logs if present (Hestia will use error.log and access.log)
  63. [ -f /var/log/$OSAL_PKG_APACHE/access_log ] && hestia_safe_rm /var/log/$OSAL_PKG_APACHE/access_log
  64. [ -f /var/log/$OSAL_PKG_APACHE/error_log ] && hestia_safe_rm /var/log/$OSAL_PKG_APACHE/error_log
  65. # Mitigation for some Debian-only scripts
  66. [ ! -e /etc/httpd/mods-enabled ] && ln -s /etc/httpd/conf.modules.d/ /etc/httpd/mods-enabled
  67. fi
  68. touch /var/log/$OSAL_PKG_APACHE/access.log /var/log/$OSAL_PKG_APACHE/error.log
  69. mkdir -p /var/log/$OSAL_PKG_APACHE/domains
  70. chmod a+x /var/log/$OSAL_PKG_APACHE
  71. chmod 640 /var/log/$OSAL_PKG_APACHE/access.log /var/log/$OSAL_PKG_APACHE/error.log
  72. chmod 751 /var/log/$OSAL_PKG_APACHE/domains
  73. osal_kv_write $HESTIA_CONF_MODULES/apache.conf 'service_name' $OSAL_SERVICE_APACHE
  74. }