apache-2.4.sh 5.5 KB

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