apache-2.2.sh 5.5 KB

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