apache-2.2.sh 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # Blog: http://blog.linuxeye.com
  4. Install_Apache-2-2()
  5. {
  6. cd $oneinstack_dir/src
  7. . ../functions/download.sh
  8. . ../functions/check_os.sh
  9. . ../options.conf
  10. src_url=http://www.apache.org/dist/httpd/httpd-$apache_2_version.tar.gz && Download_src
  11. id -u $run_user >/dev/null 2>&1
  12. [ $? -ne 0 ] && useradd -M -s /sbin/nologin $run_user
  13. tar xzf httpd-$apache_2_version.tar.gz
  14. cd httpd-$apache_2_version
  15. [ ! -d "$apache_install_dir" ] && mkdir -p $apache_install_dir
  16. ./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
  17. make && make install
  18. if [ -d "$apache_install_dir/conf" ];then
  19. echo -e "\033[32mApache install successfully! \033[0m"
  20. else
  21. rm -rf $apache_install_dir
  22. echo -e "\033[31mApache install failed, Please contact the author! \033[0m"
  23. kill -9 $$
  24. fi
  25. [ -z "`grep ^'export PATH=' /etc/profile`" ] && echo "export PATH=$apache_install_dir/bin:\$PATH" >> /etc/profile
  26. [ -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
  27. . /etc/profile
  28. cd ..
  29. [ -d "$apache_install_dir/conf" ] && /bin/rm -rf httpd-$apache_2_version
  30. /bin/cp $apache_install_dir/bin/apachectl /etc/init.d/httpd
  31. sed -i '2a # chkconfig: - 85 15' /etc/init.d/httpd
  32. sed -i '3a # description: Apache is a World Wide Web server. It is used to serve' /etc/init.d/httpd
  33. chmod +x /etc/init.d/httpd
  34. OS_CentOS='chkconfig --add httpd \n
  35. chkconfig httpd on'
  36. OS_Debian_Ubuntu='update-rc.d httpd defaults'
  37. OS_command
  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" == '3' ];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=$local_IP
  44. elif [ "$Nginx_version" == '1' -o "$Nginx_version" == '2' ];then
  45. sed -i 's/^#ServerName www.example.com:80/ServerName 127.0.0.1:9090/' $apache_install_dir/conf/httpd.conf
  46. sed -i 's@^Listen.*@Listen 127.0.0.1:9090@' $apache_install_dir/conf/httpd.conf
  47. TMP_PORT=9090
  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@^#LoadModule rewrite_module@LoadModule rewrite_module@' $apache_install_dir/conf/httpd.conf
  52. sed -i 's@^#LoadModule\(.*\)mod_deflate.so@LoadModule\1mod_deflate.so@' $apache_install_dir/conf/httpd.conf
  53. sed -i 's@DirectoryIndex index.html@DirectoryIndex index.html index.php@' $apache_install_dir/conf/httpd.conf
  54. sed -i "s@^DocumentRoot.*@DocumentRoot \"$wwwroot_dir/default\"@" $apache_install_dir/conf/httpd.conf
  55. sed -i "s@^<Directory \"$apache_install_dir/htdocs\">@<Directory \"$wwwroot_dir/default\">@" $apache_install_dir/conf/httpd.conf
  56. sed -i "s@^#Include conf/extra/httpd-mpm.conf@Include conf/extra/httpd-mpm.conf@" $apache_install_dir/conf/httpd.conf
  57. #logrotate apache log
  58. cat > /etc/logrotate.d/apache << EOF
  59. $wwwlogs_dir/*apache.log {
  60. daily
  61. rotate 5
  62. missingok
  63. dateext
  64. compress
  65. notifempty
  66. sharedscripts
  67. postrotate
  68. [ -f $apache_install_dir/logs/httpd.pid ] && kill -USR1 \`cat $apache_install_dir/logs/httpd.pid\`
  69. endscript
  70. }
  71. EOF
  72. mkdir $apache_install_dir/conf/vhost
  73. cat >> $apache_install_dir/conf/vhost/0.conf << EOF
  74. NameVirtualHost *:$TMP_PORT
  75. <VirtualHost *:$TMP_PORT>
  76. ServerAdmin admin@linuxeye.com
  77. DocumentRoot "$wwwroot_dir/default"
  78. ServerName $TMP_IP
  79. ErrorLog "$wwwlogs_dir/error_apache.log"
  80. CustomLog "$wwwlogs_dir/access_apache.log" common
  81. <Directory "$wwwroot_dir/default">
  82. SetOutputFilter DEFLATE
  83. Options FollowSymLinks
  84. AllowOverride All
  85. Order allow,deny
  86. Allow from all
  87. DirectoryIndex index.html index.php
  88. </Directory>
  89. </VirtualHost>
  90. EOF
  91. cat >> $apache_install_dir/conf/httpd.conf <<EOF
  92. ServerTokens ProductOnly
  93. ServerSignature Off
  94. AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml text/javascript
  95. DeflateCompressionLevel 6
  96. SetOutputFilter DEFLATE
  97. Include conf/vhost/*.conf
  98. EOF
  99. if [ "$Nginx_version" != '3' ];then
  100. mkdir mod_remoteip;cd mod_remoteip
  101. src_url=https://raw.githubusercontent.com/ttkzw/mod_remoteip-httpd22/master/mod_remoteip.c && Download_src
  102. $apache_install_dir/bin/apxs -i -c -n mod_remoteip.so mod_remoteip.c
  103. cat > $apache_install_dir/conf/extra/httpd-remoteip.conf << EOF
  104. LoadModule remoteip_module modules/mod_remoteip.so
  105. RemoteIPHeader X-Forwarded-For
  106. `ifconfig | awk -F"[: ]+" '/inet addr/{print "RemoteIPInternalProxy " $4}'`
  107. EOF
  108. 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
  109. cd ..
  110. fi
  111. cd ..
  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. }