apache-2.2.sh 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://blog.linuxeye.com
  4. #
  5. # Notes: OneinStack for CentOS/RadHat 5+ Debian 6+ and Ubuntu 12+
  6. #
  7. # Project home page:
  8. # https://oneinstack.com
  9. # https://github.com/lj2007331/oneinstack
  10. Install_Apache-2-2() {
  11. cd $oneinstack_dir/src
  12. id -u $run_user >/dev/null 2>&1
  13. [ $? -ne 0 ] && useradd -M -s /sbin/nologin $run_user
  14. tar xzf httpd-$apache_2_version.tar.gz
  15. cd httpd-$apache_2_version
  16. [ ! -d "$apache_install_dir" ] && mkdir -p $apache_install_dir
  17. [ "$ZendGuardLoader_yn" == 'y' -o "$ionCube_yn" == 'y' ] && MPM=prefork || MPM=worker
  18. ./configure --prefix=$apache_install_dir --enable-headers --enable-deflate --enable-mime-magic --enable-so --enable-rewrite --enable-ssl --with-ssl --enable-expires --enable-static-support --enable-suexec --disable-userdir --with-included-apr --with-mpm=$MPM --disable-userdir
  19. make -j ${THREAD} && make install
  20. if [ -e "$apache_install_dir/conf/httpd.conf" ];then
  21. echo "${CSUCCESS}Apache installed successfully! ${CEND}"
  22. cd ..
  23. rm -rf httpd-$apache_2_version
  24. else
  25. rm -rf $apache_install_dir
  26. echo "${CFAILURE}Apache install failed, Please contact the author! ${CEND}"
  27. kill -9 $$
  28. fi
  29. [ -z "`grep ^'export PATH=' /etc/profile`" ] && echo "export PATH=$apache_install_dir/bin:\$PATH" >> /etc/profile
  30. [ -n "`grep ^'export PATH=' /etc/profile`" -a -z "`grep $apache_install_dir /etc/profile`" ] && sed -i "s@^export PATH=\(.*\)@export PATH=$apache_install_dir/bin:\1@" /etc/profile
  31. . /etc/profile
  32. /bin/cp $apache_install_dir/bin/apachectl /etc/init.d/httpd
  33. sed -i '2a # chkconfig: - 85 15' /etc/init.d/httpd
  34. sed -i '3a # description: Apache is a World Wide Web server. It is used to serve' /etc/init.d/httpd
  35. chmod +x /etc/init.d/httpd
  36. [ "$OS" == 'CentOS' ] && { chkconfig --add httpd; chkconfig httpd on; }
  37. [[ $OS =~ ^Ubuntu$|^Debian$ ]] && update-rc.d httpd defaults
  38. sed -i "s@^User daemon@User $run_user@" $apache_install_dir/conf/httpd.conf
  39. sed -i "s@^Group daemon@Group $run_user@" $apache_install_dir/conf/httpd.conf
  40. if [ "$Nginx_version" == '4' -a ! -e "$web_install_dir/sbin/nginx" ];then
  41. sed -i 's/^#ServerName www.example.com:80/ServerName 0.0.0.0:80/' $apache_install_dir/conf/httpd.conf
  42. TMP_PORT=80
  43. TMP_IP=$IPADDR
  44. elif [[ $Nginx_version =~ ^[1-3]$ ]] || [ -e "$web_install_dir/sbin/nginx" ];then
  45. sed -i 's/^#ServerName www.example.com:80/ServerName 127.0.0.1:88/' $apache_install_dir/conf/httpd.conf
  46. sed -i 's@^Listen.*@Listen 127.0.0.1:88@' $apache_install_dir/conf/httpd.conf
  47. TMP_PORT=88
  48. TMP_IP=127.0.0.1
  49. fi
  50. sed -i "s@AddType\(.*\)Z@AddType\1Z\n AddType application/x-httpd-php .php .phtml\n AddType application/x-httpd-php-source .phps@" $apache_install_dir/conf/httpd.conf
  51. sed -i "s@#AddHandler cgi-script .cgi@AddHandler cgi-script .cgi .pl@" $apache_install_dir/conf/httpd.conf
  52. sed -i 's@DirectoryIndex index.html@DirectoryIndex index.html index.php@' $apache_install_dir/conf/httpd.conf
  53. sed -i "s@^DocumentRoot.*@DocumentRoot \"$wwwroot_dir/default\"@" $apache_install_dir/conf/httpd.conf
  54. sed -i "s@^<Directory \"$apache_install_dir/htdocs\">@<Directory \"$wwwroot_dir/default\">@" $apache_install_dir/conf/httpd.conf
  55. sed -i "s@^#Include conf/extra/httpd-mpm.conf@Include conf/extra/httpd-mpm.conf@" $apache_install_dir/conf/httpd.conf
  56. #logrotate apache log
  57. cat > /etc/logrotate.d/apache << EOF
  58. $wwwlogs_dir/*apache.log {
  59. daily
  60. rotate 5
  61. missingok
  62. dateext
  63. compress
  64. notifempty
  65. sharedscripts
  66. postrotate
  67. [ -f $apache_install_dir/logs/httpd.pid ] && kill -USR1 \`cat $apache_install_dir/logs/httpd.pid\`
  68. endscript
  69. }
  70. EOF
  71. mkdir $apache_install_dir/conf/vhost
  72. cat >> $apache_install_dir/conf/vhost/0.conf << EOF
  73. NameVirtualHost *:$TMP_PORT
  74. <VirtualHost *:$TMP_PORT>
  75. ServerAdmin admin@linuxeye.com
  76. DocumentRoot "$wwwroot_dir/default"
  77. ServerName $TMP_IP
  78. ErrorLog "$wwwlogs_dir/error_apache.log"
  79. CustomLog "$wwwlogs_dir/access_apache.log" common
  80. <Directory "$wwwroot_dir/default">
  81. SetOutputFilter DEFLATE
  82. Options FollowSymLinks ExecCGI
  83. AllowOverride All
  84. Order allow,deny
  85. Allow from all
  86. DirectoryIndex index.html index.php
  87. </Directory>
  88. <Location /server-status>
  89. SetHandler server-status
  90. Order Deny,Allow
  91. Deny from all
  92. Allow from 127.0.0.1
  93. </Location>
  94. </VirtualHost>
  95. EOF
  96. cat >> $apache_install_dir/conf/httpd.conf <<EOF
  97. <IfModule mod_headers.c>
  98. AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml text/javascript
  99. <FilesMatch "\.(js|css|html|htm|png|jpg|swf|pdf|shtml|xml|flv|gif|ico|jpeg)\$">
  100. RequestHeader edit "If-None-Match" "^(.*)-gzip(.*)\$" "\$1\$2"
  101. Header edit "ETag" "^(.*)-gzip(.*)\$" "\$1\$2"
  102. </FilesMatch>
  103. DeflateCompressionLevel 6
  104. SetOutputFilter DEFLATE
  105. </IfModule>
  106. ServerTokens ProductOnly
  107. ServerSignature Off
  108. Include conf/vhost/*.conf
  109. EOF
  110. if [ "$Nginx_version" != '4' -o -e "$web_install_dir/sbin/nginx" ];then
  111. $apache_install_dir/bin/apxs -i -c -n mod_remoteip.so mod_remoteip.c
  112. cat > $apache_install_dir/conf/extra/httpd-remoteip.conf << EOF
  113. LoadModule remoteip_module modules/mod_remoteip.so
  114. RemoteIPHeader X-Forwarded-For
  115. RemoteIPInternalProxy 127.0.0.1
  116. EOF
  117. sed -i "s@Include conf/extra/httpd-mpm.conf@Include conf/extra/httpd-mpm.conf\nInclude conf/extra/httpd-remoteip.conf@" $apache_install_dir/conf/httpd.conf
  118. fi
  119. ldconfig
  120. service httpd start
  121. cd ..
  122. }