httpd编译安装

  1. httpd编译安装  
  2. ===========================================  
  3. 官网:http://httpd.apache.org/  
  4. 包:httpd-2.4.20.tar.bz2     
  5. 注释:此处只考虑 2.4+ 的安装与配置,基于CentOS 6 和 CentOS 7。  
  6.   
  7. (1)环境准备。  
  8.     ~]# yum -y install gcc gcc-c++ apr-devel apr-util-devel pcre pcre-devel openssl openssl-devel  
  9.     ~]# tar -axf httpd-2.4.20.tar.bz2  
  10.     ~]# cd httpd-2.4.20/  
  11.   
  12. (2)注意事项。  
  13.     CentOS 6:注意事项  
  14.         apr 与 apr-util 官网下载地址:http://apr.apache.org/download.cgi  
  15.         版本要求:  
  16.             (1) apr             version >= 1.4+  
  17.                 ~]# ./configure  --prefix=/usr/local/apr  
  18.                 ~]# make && make install  
  19.   
  20.             (2) apr-util        version >= 1.4+  
  21.                 ~]# ./configure  --prefix=/usr/local/apr-util  --with-apr=/usr/local/apr  
  22.                 ~]# make && make install  
  23.   
  24. (3)编译安装。  
  25.     CentOS 6:  
  26.             ~]# ./configure --prefix=/usr/local/httpd --sysconfdir=/etc/httpd --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=all --enable-mpms-shared=all --with-pcre --with-libxml2 --enable-cgi  --with-mpm=prefork  
  27.     CentOS 7:  
  28.             ~]#   ./configure --prefix=/usr/local/httpd --sysconfdir=/etc/httpd --enable-modules=all --enable-mpms-shared=all --with-pcre --with-libxml2 --enable-cgi  --with-mpm=prefork  
  29.   
  30.     ~]# make && make install  
  31.   
  32.     注释:  
  33.         (1)--enable-mods-shared=all --enable-mods-static=all 只能选择一个,选择了 shared 之后还可以选择部分 static。(非必选)  
  34.         (2) --enable-load-all-modules 开启所有的选项,不要使用,开启了所有的会存在一些冲突,当需要的时候手动开启即可。  
  35.         (2)--enable-cgi 为模块。--with-pcre --with-libxml2 为扩展。(非必选)  
  36.         (3)--with-mpm=prefork 指定默认工作模型。(非必选)  
  37.         (4)--with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util  为 CentOS 6 系统的依赖。(CentOS 6 必选)  
  38.   
  39.     查看编译了那些模块:  
  40.             ~]# ls /usr/local/httpd/modules  
  41.   
  42.     查看加载了那些模块:  
  43.             ~]# /usr/local/httpd/bin/httpd -M  
  44. ===============================================  
  45. 常用选项解释:  
  46. Configuration:  
  47.     -h, --help             显示帮助文档并退出  
  48.   
  49. Installation directories:  
  50.   --prefix=PREFIX         指定安装路径  
  51.   
  52. Fine tuning of the installation directories:  
  53.     --sysconfdir=DIR        指定配置文件路径  
  54.   
  55. Optional Features:  
  56.   --enable-load-all-modules     开启所有的加载模块  
  57.   --enable-modules=MODULE-LIST  开启模块 | "all" |"most" | "few" | "none" | "reallyall"  
  58.   --enable-mods-shared=MODULE-LIST    共享模块 |"all" | "most" | "few" | "reallyall"  
  59.   --enable-mods-static=MODULE-LIST   静态模块 |"all" | "most" | "few" | "reallyall"  
  60.   --enable-ssl            SSL/TLS :构建 https  
  61.   --enable-mpms-shared=MPM-LIST    共享模块 | "all"  
  62.   --enable-rewrite        url 重写  
  63.   --enable-vhost-alias    虚拟主机  
  64.   --enable-proxy-fcgi     FastCGI 模块  
  65.   --enable-so            允许运行时加载DSO模块  
  66.   
  67. Optional Packages:  
  68.     --with-apr=PATH         prefix for installed APR or the full path to apr-config  
  69.     --with-apr-util=PATH    prefix for installed APU or the full path to  apu-config  
  70.     --with-mpm=MPM        指定apache默认工作模式:MPM={event|worker|prefork|winnt}  
  71.     --with-pcre=PATH        perl语言兼容正则表达式)是一个用C语言编写的正则表达式函数库。  
  72.     --with-libxml2=PATH     Libxml2 是一个xml c语言版的解析器,还支持c++、PHP、Pascal、Ruby、Tcl等语言的绑定  
  73.   
  74. ========================================================  
  75. 系统服务,启动,库,环境变量等设置。  
  76.   
  77. (1)测试是否正常。  
  78.         自带启动脚本:  
  79.             /usr/local/httpd/bin/apachectl (start | stop | restart | graceful | graceful-stop)  
  80.         查看端口80是否被监听:  
  81.             ss -tnl  
  82.   
  83. (2)加入环境变量  
  84.     临时生效:  
  85.         ~]# export PATH=/usr/local/httpd/bin:$PATH  
  86.   
  87.     永久生效:  
  88.         ~]# vim /etc/profile.d/httpd.sh  
  89.            export PATH=/usr/local/httpd/bin:$PATH  
  90.         ~]# source /etc/profile.d/httpd.sh  
  91.   
  92.     测试:(apachectl 现在是一个命令)  
  93.         ~]# apachectl (start | stop | restart | graceful | graceful-stop)  
  94.   
  95. (3)导出库文件:  
  96.         ~]# ln -s /usr/local/httpd/include /usr/include/httpd  
  97.   
  98. (4)导出man手册  
  99.     CentOS 6:  
  100.         ~]# vim /etc/man.config  
  101.     CentOS 7:  
  102.         ~]# vi /etc/man_db.conf  
  103.   
  104.     写入:  
  105.         MANPATH /usr/local/httpd/man  
  106.   
  107.   
  108. (5)服务脚本文件  
  109.     CentOS 6:新加启动脚本。  
  110. ~]# vi /etc/rc.d/init.d/httpd  
  111. -------------------------------------start----------------------------------------------  
  112. #!/bin/bash  
  113. #  
  114. # httpd        Startup script for the Apache HTTP Server  
  115. #  
  116. # chkconfig: - 85 15  
  117. # description: The Apache HTTP Server is an efficient and extensible  \  
  118. #          server implementing the current HTTP standards.  
  119. # processname: httpd  
  120. # config: /etc/httpd/conf/httpd.conf  
  121. # config: /etc/sysconfig/httpd  
  122. # pidfile: /var/run/httpd/httpd.pid  
  123. #  
  124. ### BEGIN INIT INFO  
  125. # Provides: httpd  
  126. # Required-Start: $local_fs $remote_fs $network $named  
  127. # Required-Stop: $local_fs $remote_fs $network  
  128. # Should-Start: distcache  
  129. # Short-Description: start and stop Apache HTTP Server  
  130. # Description: The Apache HTTP Server is an extensible server   
  131. #  implementing the current HTTP standards.  
  132. ### END INIT INFO  
  133.   
  134. # Source function library.  
  135. . /etc/rc.d/init.d/functions  
  136.   
  137. if [ -f /etc/sysconfig/httpd ]; then  
  138.         . /etc/sysconfig/httpd  
  139. fi  
  140.   
  141. # Start httpd in the C locale by default.  
  142. HTTPD_LANG=${HTTPD_LANG-"C"}  
  143.   
  144. # This will prevent initlog from swallowing up a pass-phrase prompt if  
  145. # mod_ssl needs a pass-phrase from the user.  
  146. INITLOG_ARGS=""  
  147.   
  148. # Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server  
  149. # with the thread-based "worker" MPM; BE WARNED that some modules may not  
  150. # work correctly with a thread-based MPM; notably PHP will refuse to start.  
  151.   
  152. # Path to the apachectl script, server binary, and short-form for messages.  
  153. apachectl=/usr/local/httpd/bin/apachectl  
  154. httpd=${HTTPD-/usr/local/httpd/bin/httpd}  
  155. prog=httpd  
  156. pidfile=${PIDFILE-/usr/local/httpd/logs/httpd.pid}  
  157. lockfile=${LOCKFILE-/var/lock/subsys/httpd}  
  158. RETVAL=0  
  159. STOP_TIMEOUT=${STOP_TIMEOUT-10}  
  160.   
  161. # The semantics of these two functions differ from the way apachectl does  
  162. # things -- attempting to start while running is a failure, and shutdown  
  163. # when not running is also a failure.  So we just do it the way init scripts  
  164. # are expected to behave here.  
  165. start() {  
  166.         echo -n $"Starting $prog: "  
  167.         LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS  
  168.         RETVAL=$?  
  169.         echo  
  170.         [ $RETVAL = 0 ] && touch ${lockfile}  
  171.         return $RETVAL  
  172. }  
  173.   
  174. # When stopping httpd, a delay (of default 10 second) is required  
  175. # before SIGKILLing the httpd parent; this gives enough time for the  
  176. # httpd parent to SIGKILL any errant children.  
  177. stop() {  
  178.     echo -n $"Stopping $prog: "  
  179.     killproc -p ${pidfile} -d ${STOP_TIMEOUT} $httpd  
  180.     RETVAL=$?  
  181.     echo  
  182.     [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}  
  183. }  
  184. reload() {  
  185.     echo -n $"Reloading $prog: "  
  186.     if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then  
  187.         RETVAL=6  
  188.         echo $"not reloading due to configuration syntax error"  
  189.         failure $"not reloading $httpd due to configuration syntax error"  
  190.     else  
  191.         # Force LSB behaviour from killproc  
  192.         LSB=1 killproc -p ${pidfile} $httpd -HUP  
  193.         RETVAL=$?  
  194.         if [ $RETVAL -eq 7 ]; then  
  195.             failure $"httpd shutdown"  
  196.         fi  
  197.     fi  
  198.     echo  
  199. }  
  200.   
  201. # See how we were called.  
  202. case "$1" in  
  203.   start)  
  204.     start  
  205.     ;;  
  206.   stop)  
  207.     stop  
  208.     ;;  
  209.   status)  
  210.         status -p ${pidfile} $httpd  
  211.     RETVAL=$?  
  212.     ;;  
  213.   restart)  
  214.     stop  
  215.     start  
  216.     ;;  
  217.   condrestart|try-restart)  
  218.     if status -p ${pidfile} $httpd >&/dev/null; then  
  219.         stop  
  220.         start  
  221.     fi  
  222.     ;;  
  223.   force-reload|reload)  
  224.         reload  
  225.     ;;  
  226.   graceful|help|configtest|fullstatus)  
  227.     $apachectl $@  
  228.     RETVAL=$?  
  229.     ;;  
  230.   *)  
  231.     echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}"  
  232.     RETVAL=2  
  233. esac  
  234.   
  235. exit $RETVAL  
  236. ---------------------------------------------------end------------------------------------------------  
  237.   
  238.   
  239. CentOS 7 新加启动脚本:  
  240. ~]# vi   
  241. ---------------------------------------------------start------------------------------------------------  
  242.   
  243. ---------------------------------------------------end------------------------------------------------  
  244.   
  245.   
  246. (6)开机启动  
  247. CentOS 6:  
  248.     ~]# chkconfig --add httpd  
  249.     ~]# chkconfig --level 345 httpd on  
  250.     ~]# chkconfig --list httpd  
  251.         httpd          0:off   1:off   2:off   3:on    4:on    5:on    6:off  
  252.   
  253. CentOS 7:  
  254.       
  255.   
  256. (7)系统启动与停止  
  257.     CentOS 6:  
  258.         service httpd (start | stop | restart)  
  259.     CentOS 7:  
  260.         systemctl (start | stop | restart) httpd.service  
  261.   
  262. (7)语法测试  
  263.     httpd -t  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值