hjqjk 标签: httpd2.4 编译安装 CentOS6.5
一、当前环境;
系统和内核版本:
系统的httpd版本:
二、在CentOS6.5中编译安装httpd2.4
1、准备环境
安装httpd前需准备的程序包组;这几个程序包系统自带光盘就有,只需挂载到指定目录,制作成本地yum源即可安装使用。(此处不做过多介绍)
解决依赖关系:
[root@localhost ~]# yum groupinstall -y "Server Platform Development" [root@localhost ~]# yum groupinstall -y "Development tools" [root@localhost ~]# yum install -y pcre-devel-7.8-6.el6.x86_642、编译安装httpd2.4及httpd2.4所依赖的软件包
如果CentOS6.5系统中httpd服务已经启动了,先停止httpd服务
[root@localhost ~]# service httpd stop
(1)简单介绍
CentOS7默认安装httpd2.4。
CentOS6用的是httpd2.2,CentOS6中默认的库和开发工具不支持使用httpd2.4。想要在CentOS6中安装httpd2.4,就要更新更高版本的apr和apr-util。
APR(Apache portable Run-time libraries,Apache可移植运行库)的目的如其名称一样,主要为上层的应用程序提供一个可以跨越多操作系统平台使用的底层支持接口库。它是个能够让Apache跨平台工作的工具,是个底层库,安装上apr后。如果在win和linux上安装上apr后,Apache的同一个代码,即可以在win上运行也可在linux上运行;
当前CentOS6.5的apr版本:
httpd2.4依赖于更高版本的apr和apr-util(要是1.4或1.4以上的版本)。
(2)下载最新版的httpd、apr和apr-util
[root@localhost ~]# wget http://apache.fayea.com/apache-mirror//httpd/httpd-2.4.9.tar.bz2
[root@localhost ~]# wget http://mirrors.hust.edu.cn/apache//apr/apr-1.5.0.tar.gz
[root@localhost ~]# wget http://mirrors.hust.edu.cn/apache//apr/apr-util-1.5.3.tar.gz
(3)编译安装apr-1.5.0
[root@localhost ~]# tar xf apr-1.5.0.tar.bz2 [root@localhost ~]# cd apr-1.5.0 [root@localhost apr-1.5.0]# ./configure --prefix=/usr/local/apr [root@localhost apr-1.5.0]# make && make install
基于编译安装,会把所有的环境和开发工具装上,不同于rpm有子包的概念。
(4)编译安装apr-util-1.5.3
[root@localhost ~]# tar xf apr-util-1.5.3.tar.bz2 [root@localhost ~]# cd apr-util-1.5.3 [root@localhost apr-util-1.5.3]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr [root@localhost apr-util-1.5.3]# make && make install
因为apr-util-1.5.3是作为apr-1.5.0的工具使用的,所以要用--with-apr选项指定apr的安装目录。
(5)编译安装httpd-2.4.9
[root@localhost ~]# tar xf httpd-2.4.9.tar.bz2 [root@localhost ~]# cd httpd-2.4.9 [root@localhost httpd-2.4.9]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enable-mpms-shared=all --with-mpm=event --enable-modules=most [root@localhost httpd-2.4.9]# make && make install
选项解释:
--prefix=/usr/local/apache 安装路径
--sysconfdir=/etc/httpd24 配置文件路径
--enable-so 允许运行时加载DSO模块
--enable-ssl 如果不加载将无法使用使用https
--enable-cgi 允许使用cgi脚本
--enable-rewrite 支持URL重写机制
--with-zlib 支持网络通用压缩库
--with-pcre 支持pcre
--with-apr=/usr/local/apr 指定apr的安装路径
--with-apr-util=/usr/local/apr-util/ 指定apr-util的安装路径
--enable-mpms-shared=all 启用MPM所有支持的模式
--with-mpm=event 默认使用enevt模式
--enable-modules=most 启用大多数常用的模块
查看安装后所生成的文件,extra目录是2.4版新增目录
3、编译后所需的配置
(1)导出二进制程序
[root@localhost ~]# vim /etc/profile.d/httpd24.sh [root@localhost ~]# cat /etc/profile.d/httpd24.sh export PATH=/usr/local/apache/bin:$PATH [root@localhost ~]# source /etc/profile.d/httpd24.sh [root@localhost ~]# echo $PATH /usr/local/apache/bin:/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin [root@localhost ~]# httpd -v Server version: Apache/2.4.9 (Unix) Server built: Aug 9 2014 06:00:59(2)启动httpd服务并测试是否已经导出二进制程序
[root@localhost ~]# apachectl start测试是否成功导出二进制程序:
(注意:httpd2.4是使用apachectl命令来启动服务的。)
测试成功!
(3)导出头文件;以目录链接的形式来实现
[root@localhost ~]# ln -sv /usr/local/apache/include /usr/include/httpd24 `/usr/include/httpd24' -> `/usr/local/apache/include'注意:可以把一个目录链接到一个文件中
(头文件主要是用于二次开发)
(4)导出man文件
[root@localhost ~]# vim /etc/man.config在/etc/man.config配置文件中添加如下代码:
MANPATH /usr/local/apache/man
测试是否成功:
[root@localhost ~]# man -M /usr/local/apache/man httpd [root@localhost ~]# man httpd(5)提供httpd服务脚本
[root@localhost ~]# vim /etc/rc.d/init.d/httpd24修改服务配置文件,先把httpd服务停止
[root@localhost init.d]# apachectl stop httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName httpd (no pid file) not running
脚本如下:
#!/bin/bash # # httpd Startup script for the Apache HTTP Server # # chkconfig: - 85 15 # description: The Apache HTTP Server is an efficient and extensible \ # server implementing the current HTTP standards. # processname: httpd # config: /etc/httpd/conf/httpd.conf # config: /etc/sysconfig/httpd # pidfile: /var/run/httpd/httpd.pid # ### BEGIN INIT INFO # Provides: httpd # Required-Start: $local_fs $remote_fs $network $named # Required-Stop: $local_fs $remote_fs $network # Should-Start: distcache # Short-Description: start and stop Apache HTTP Server # Description: The Apache HTTP Server is an extensible server # implementing the current HTTP standards. ### END INIT INFO # Source function library. . /etc/rc.d/init.d/functions #if [ -f /etc/sysconfig/httpd ]; then # . /etc/sysconfig/httpd #fi # Start httpd in the C locale by default. HTTPD_LANG=${HTTPD_LANG-"C"} # This will prevent initlog from swallowing up a pass-phrase prompt if# mod_ssl needs a pass-phrase from the user. INITLOG_ARGS="" # Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server # with the thread-based "worker" MPM; BE WARNED that some modules may not # work correctly with a thread-based MPM; notably PHP will refuse to start. # Path to the apachectl script, server binary, and short-form for messages. apachectl=/usr/local/apache/bin/apachectl #指定新的apachectl脚本的位置httpd=${HTTPD-/usr/local/apache/bin/httpd} #指定新的httpd程序的位置 prog=httpd pidfile=${PIDFILE-/usr/local/apache/logs/httpd.pid} #指定新的httpd服务的进程文件lockfile=${LOCKFILE-/var/lock/subsys/httpd} RETVAL=0 STOP_TIMEOUT=${STOP_TIMEOUT-10} # The semantics of these two functions differ from the way apachectl does # things -- attempting to start while running is a failure, and shutdown # when not running is also a failure. So we just do it the way init scripts # are expected to behave here. start() { echo -n $"Starting $prog: " LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS RETVAL=$? echo [ $RETVAL = 0 ] && touch ${lockfile}return $RETVAL } # When stopping httpd, a delay (of default 10 second) is required # before SIGKILLing the httpd parent; this gives enough time for the # httpd parent to SIGKILL any errant children. stop() { echo -n $"Stopping $prog: " killproc -p ${pidfile} -d ${STOP_TIMEOUT} $httpd RETVAL=$? echo [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile} } reload() { echo -n $"Reloading $prog: "if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then RETVAL=6 echo $"not reloading due to configuration syntax error" failure $"not reloading $httpd due to configuration syntax error"else# Force LSB behaviour from killproc LSB=1 killproc -p ${pidfile} $httpd -HUP RETVAL=$?if [ $RETVAL -eq 7 ]; then failure $"httpd shutdown" fi fi echo } # See how we were called.case "$1" in start) start ;; stop) stop ;; status) status -p ${pidfile} $httpd RETVAL=$? ;; restart) stop start ;; condrestart|try-restart)if status -p ${pidfile} $httpd >&/dev/null; then stop start fi ;; force-reload|reload) reload ;; graceful|help|configtest|fullstatus) $apachectl $@ RETVAL=$? ;; *) echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}" RETVAL=2 esac exit $RETVAL测试:
[root@localhost ~]# chkconfig --add httpd24 [root@localhost ~]# chkconfig --list httpd24 httpd24 0:off 1:off 2:off 3:off 4:off 5:off 6:off [root@localhost ~]# service httpd24 start Starting httpd: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message [ OK ] [root@localhost ~]# service httpd24 stop Stopping httpd: [ OK ]测试成功!