apache-2.2.sh 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. {
  12. cd $oneinstack_dir/src
  13. src_url=http://www.apache.org/dist/httpd/httpd-$apache_2_version.tar.gz && Download_src
  14. id -u $run_user >/dev/null 2>&1
  15. [ $? -ne 0 ] && useradd -M -s /sbin/nologin $run_user
  16. tar xzf httpd-$apache_2_version.tar.gz
  17. cd httpd-$apache_2_version
  18. [ ! -d "$apache_install_dir" ] && mkdir -p $apache_install_dir
  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=prefork --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 \n
  38. chkconfig httpd on'
  39. OS_Debian_Ubuntu='update-rc.d httpd defaults'
  40. OS_command
  41. sed -i "s@^User daemon@User $run_user@" $apache_install_dir/conf/httpd.conf
  42. sed -i "s@^Group daemon@Group $run_user@" $apache_install_dir/conf/httpd.conf
  43. if [ "$Nginx_version" == '3' ];then
  44. sed -i 's/^#ServerName www.example.com:80/ServerName 0.0.0.0:80/' $apache_install_dir/conf/httpd.conf
  45. TMP_PORT=80
  46. TMP_IP=$IPADDR
  47. elif [ "$Nginx_version" == '1' -o "$Nginx_version" == '2' ];then
  48. sed -i 's/^#ServerName www.example.com:80/ServerName 127.0.0.1:9090/' $apache_install_dir/conf/httpd.conf
  49. sed -i 's@^Listen.*@Listen 127.0.0.1:9090@' $apache_install_dir/conf/httpd.conf
  50. TMP_PORT=9090
  51. TMP_IP=127.0.0.1
  52. fi
  53. 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
  54. sed -i 's@^#LoadModule rewrite_module@LoadModule rewrite_module@' $apache_install_dir/conf/httpd.conf
  55. sed -i 's@^#LoadModule\(.*\)mod_deflate.so@LoadModule\1mod_deflate.so@' $apache_install_dir/conf/httpd.conf
  56. sed -i 's@DirectoryIndex index.html@DirectoryIndex index.html index.php@' $apache_install_dir/conf/httpd.conf
  57. sed -i "s@^DocumentRoot.*@DocumentRoot \"$wwwroot_dir/default\"@" $apache_install_dir/conf/httpd.conf
  58. sed -i "s@^<Directory \"$apache_install_dir/htdocs\">@<Directory \"$wwwroot_dir/default\">@" $apache_install_dir/conf/httpd.conf
  59. sed -i "s@^#Include conf/extra/httpd-mpm.conf@Include conf/extra/httpd-mpm.conf@" $apache_install_dir/conf/httpd.conf
  60. #logrotate apache log
  61. cat > /etc/logrotate.d/apache << EOF
  62. $wwwlogs_dir/*apache.log {
  63. daily
  64. rotate 5
  65. missingok
  66. dateext
  67. compress
  68. notifempty
  69. sharedscripts
  70. postrotate
  71. [ -f $apache_install_dir/logs/httpd.pid ] && kill -USR1 \`cat $apache_install_dir/logs/httpd.pid\`
  72. endscript
  73. }
  74. EOF
  75. mkdir $apache_install_dir/conf/vhost
  76. cat >> $apache_install_dir/conf/vhost/0.conf << EOF
  77. NameVirtualHost *:$TMP_PORT
  78. <VirtualHost *:$TMP_PORT>
  79. ServerAdmin admin@linuxeye.com
  80. DocumentRoot "$wwwroot_dir/default"
  81. ServerName $TMP_IP
  82. ErrorLog "$wwwlogs_dir/error_apache.log"
  83. CustomLog "$wwwlogs_dir/access_apache.log" common
  84. <Directory "$wwwroot_dir/default">
  85. SetOutputFilter DEFLATE
  86. Options FollowSymLinks
  87. AllowOverride All
  88. Order allow,deny
  89. Allow from all
  90. DirectoryIndex index.html index.php
  91. </Directory>
  92. </VirtualHost>
  93. EOF
  94. cat >> $apache_install_dir/conf/httpd.conf <<EOF
  95. ServerTokens ProductOnly
  96. ServerSignature Off
  97. AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml text/javascript
  98. DeflateCompressionLevel 6
  99. SetOutputFilter DEFLATE
  100. Include conf/vhost/*.conf
  101. EOF
  102. if [ "$Nginx_version" != '3' ];then
  103. src_url=https://raw.githubusercontent.com/ttkzw/mod_remoteip-httpd22/master/mod_remoteip.c && Download_src
  104. $apache_install_dir/bin/apxs -i -c -n mod_remoteip.so mod_remoteip.c
  105. cat > $apache_install_dir/conf/extra/httpd-remoteip.conf << EOF
  106. LoadModule remoteip_module modules/mod_remoteip.so
  107. RemoteIPHeader X-Forwarded-For
  108. RemoteIPInternalProxy 127.0.0.1
  109. EOF
  110. 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
  111. fi
  112. [ "$Nginx_version" == '3' -a "$Apache_version" != '3' ] && sed -i "s@^web_install_dir.*@web_install_dir=$apache_install_dir@" options.conf
  113. service httpd start
  114. cd ..
  115. }