apache-2.4.sh 5.5 KB

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