web:4、编译安装httpd-2.4及其新特性

1、环境

OS:CentOS6.7-x86_64

2、安装依赖包

httpd-2.4依赖于较高版本的apr(1.5以上)和apr-util

apr:apache portable runtime(移植运行)是一个api,一个底层库,让apache能够跨平台的工具。

apache支持正则表达式依赖于pcre(正则表达式函数库),安装其开发包pcre-devel即可

注意:可以不卸载系统上yum安装httpd和其依赖包,但一定要关闭httpd并禁止其开机启动。建议删掉

源码包下载地址:

最新稳定版:httpd-2.4.17  http://httpd.apache.org/download.cgi#apache24

       apr-1.5.2,apr-util-1.5.4  http://apr.apache.org/download.cgi

 1)安装编译工具gcc,gcc-c++及pcre-devel

[root@BAIYU_179 ~]# yum install gcc gcc-c++ #安装编译工具
[root@BAIYU_179 ~]# yum install pcre-devel -y

 2)编译安装apr-1.5.0

[root@BAIYU_179 ~]# cd src/
[root@BAIYU_179 src]# ls
apr-1.5.0.tar.bz2  apr-util-1.5.3.tar.bz2  httpd-2.4.9.tar.bz2
[root@BAIYU_179 src]# tar xf apr-1.5.0.tar.bz2 
[root@BAIYU_179 src]# cd apr-1.5.0
[root@BAIYU_179 apr-1.5.0]# ./configure --with-included-apr --prefix=/usr/local/apr
[root@BAIYU_179 apr-1.5.0]# make && make install

 3)编译安装apr-util-1.5.3

[root@BAIYU_179 src]# tar -xf apr-util-1.5.3.tar.bz2 
[root@BAIYU_179 src]# cd apr-util-1.5.3
[root@BAIYU_179 apr-util-1.5.3]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr      #apr-util依赖于apr所以要指定apr安装的位置
[root@BAIYU_179 apr-util-1.5.3]# make && make install

3、编译安装httpd-2.4.9

[root@BAIYU_179 apr-util-1.5.3]# cd ..
[root@BAIYU_179 src]# tar xf httpd-2.4.9.tar.bz2 
[root@BAIYU_179 src]# cd httpd-2.4.9
[root@BAIYU_179 httpd-2.4.9]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd2.4 --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-modules=most --enable-mpms-shared=all --with-mpm=event
[root@BAIYU_179 httpd-2.4.9]# make && make install

Apache编译参数详解:

--prefix=/usr/local/apache  #指定安装目标路径
--sysconfdir=/etc/httpd     #指定配置文件安装位置
--enable-so                 #支持动态共享模块
--enable-cgi                #启用支持cgi
--enable-rewirte            #支持URL重写
 --with-zlib                #网络上发送数据报文时通用压缩库的API
--enable-ssl                #启用支持ssl
--with-apr=/usr/local/apr   #指定依赖包apr路径
--with-apr-util=/usr/local/apr-util  #指定依赖包apr-util路径
--enable-modules=all|most            #安装全部模块或大多数模块
--enable-mpms-shared=all             #以动态共享模块方式安装全部MPM
--with-event:                        #指定默认使用event

4、启动并测试

[root@BAIYU_179 apache]# bin/apachectl start

wKiom1Y4corh2BaPAAB0ypqQn_8270.jpg

5、后续的配置

 1)导出头文件

[root@BAIYU_179 apache]# ln -sv /usr/local/apache/include/ /usr/include/httpd
"/usr/include/httpd" -> "/usr/local/apache/include/"

 2)导出库文件(没有生成库文件)


 3)导出man手册

 # vi /etc/man.conf 
添加 MANPATH /usr/local/apache/man
或者直接使用命令:man -M /usr/local/apache/man apache

 4)导出二进制程序

# vi /etc/profile.d/httpd.sh
添加  export PATH=/usr/local/apache/bin:$PATH

 5)创建SysV(System V)风格的服务脚本

最简单的方法是修改原yum安装的httpd服务脚本

在/etc/httpd2.4/httpd.conf中添加一行:PidFile "/var/run/httpd2.4.pid"

修改原yum安装的http服务脚本:/etc/rc.d/init.d/httpd

 42 apachectl=/usr/local/apache/bin/apachectl   #将对应的行修改成这个即可
 43 httpd=/usr/local/apache/bin/httpd
 44 prog=httpd
 45 pidfile=${PIDFILE-/var/run/httpd2.4.pid}
 
 [root@BAIYU_179 init.d]# service httpd start
正在启动 httpd:AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.100.179. Set the 'ServerName' directive globally to suppress this message
[确定]

注意:

编译安装2.4版本的主配置文件/etc/apache2.4没有像yum安装的2.2版本的主配置文件/etc/httpd/conf/httpd.conf一样分为三段,分段配置文件为/etc/apache2.4/extra/*.conf

[root@BAIYU_179 httpd2.4]# ls
extra  httpd.conf  magic  mime.types  original
[root@BAIYU_179 httpd2.4]# cd extra/
[root@BAIYU_179 extra]# ls
httpd-autoindex.conf  httpd-info.conf       httpd-mpm.conf                 httpd-userdir.conf
httpd-dav.conf        httpd-languages.conf  httpd-multilang-errordoc.conf  httpd-vhosts.conf
httpd-default.conf    httpd-manual.conf     httpd-ssl.conf                 proxy-html.conf

httpd-vhost.conf配置虚拟主机

httpd-ssl.conf:配置ssl

httpd-mpm.conf:配置MPM

6、httpd-2.4新特性

 1)MPM支持在运行时装载:

   --enable-mpms-shared=all(编译所有支持的MPM) --with-mpm=event(设定默认启用的MPM)

 2)支持event

 3)异步读写

 4)在每模块及每目录上指定日志级别

 5)每请求配置:<If>,<Elseif>

 6)增强版的表达分析器

 7)毫秒级的keepalive timout

 8)基于FQDN的虚拟主机不再需要NameVirtualHost指令

 9)配置文件支持使用自定义变量

   新增了一些模块:mod_proxy_fcgi,mod_ratelimit,mod_request,mod_remoteip

  对于基于IP的访问控制做了修改:不再支持用order,allow,deny这些机制而是统一使用require进行;中心主机和虚拟主机都必须明确定义权限才可以访问,否则无权限访问

7、基于IP访问控制

   允许所有主机访问:Require all granted

   拒绝所有主机访问:Require all deny

   控制某主机的访问:

       Require ip IPADDR

       Require not ip IPADDR

               IPADDR可使用的格式:

                    单个IP地址,例如:172.16.100.7

                network/netmask 例如:172.16.0.0/255.255.0.0

                 network/Length 例如:172.16.0.0/16

                            Net 例如:172.16              

       Require host IPADDR

       Require not host IPADDR

                Hostname可使用的格式:

                           FQDN:具体的主机

                         DOMAIN: 域名,例如:.magedu.com                            

8、编译过程中常见的报错及解决方法:

 1)支持ssl而没有安装openssl-devel

checking for OpenSSL version >= 0.9.7… FAILED
configure: WARNING: OpenSSL version is too old
no
checking whether to enable mod_ssl… configure: error: mod_ssl has been requested but cannot be built due to prerequisite failures

解决方法:

yum install openssl-devel

注意:这里不能使用光盘yum源,否则会报错,安装不了

2)编译安装apr时没有加上“--with-included-apr”导致编译安装httpd时报错

exports.c:2454: error: redefinition of 'ap_hack_apu_version_string'
exports.c:2038: note: previous definition of 'ap_hack_apu_version_string' was here
make[2]: *** [exports.lo] 错误 1
make[2]: Leaving directory `/root/src/httpd-2.4.9/server'
make[1]: *** [all-recursive] 错误 1
make[1]: Leaving directory `/root/src/httpd-2.4.9/server'
make: *** [all-recursive] 错误 1
[root@BAIYU_179 httpd-2.4.9]#

解决方法:

    编译安装apr时加上“--with-included-apr”即可

 # ./configure --with-included-apr --prefix=/usr/local/apr
 # make && make install

3)make install时出错 

/bin/sh /usr/local/httpd-2.2.3/srclib/apr/libtool --mode=install /usr/bin/install -c -m 755 libaprutil-1.la /usr/local/apache2/lib
libtool: install: error: cannot install `libaprutil-1.la' to a directory not ending in /usr/local/apache2/lib  www.2cto.com  
make[2]: *** [install] Error 1

可能是因为之前安装用过./configure参数写错了,导致安装文件已经不太“干净”,再次./configure之前没make clean 

解决方法:

    执行make clean后,重新./configure


你可能感兴趣的:(apache,httpd)