apache httpd 2.4.9编译安装:

系统基础:centos x64
已有apache版本:2.2.4
已有apr1.2、apr-uitl1.2、pcre

现需安装apache httpd 2.4.9

1、备好安装包:
apr-1.5.0.tar.gz,apr-util-1.5.3.tar.gz,pcre-8.35.tar.gz,httpd-2.4.9.tar.bz2
httpd-2.4.9需要用到最新的apr和apr-util版本,可到www.apache.org下载

2、安装apr-1.5.0:
tar -zxvf apr-1.5.0.tar.gz  #解压apr安装包

./configure --prefix=/usr/local/apr  #检查

提示:config.status:creating include/arch/unix/apr_private.h
     config.status:excuting libtool commands
     rm:cannot remove 'libtoolT': NO such file or directory
     config.status:executing default commands
(这个提示可不理会,继续安装)

make && make install  #编译 安装

3、安装apr-util-1.5.3:
tar -zxvf apr-util-1.5.3.tar.gz  #解压

./configure --prefix=/usr/local/apr-util  --with-apr=/usr/local/apr  #检查

make && make install  #编译 安装

4、安装pcre-8.35.tar.gz:
tar -zxvf pcre-8.35.tar.gz  #解压

./configure --prefix=/usr/local/pcre  #检查

make && make install  #编译 安装

注意,如不安装pcre包 安装apache httpd的时候会提示如下错误:
util_pcre.c:128: error: 'PCRE_DUPNAMES' undeclared (first use in this function)
util_pcre.c:128: error: (Each undeclared identifier is reported only once
util_pcre.c:128: error: for each function it appears in.)
make[2]: *** [util_pcre.lo] 错误 1
make[2]: Leaving directory `/software/httpd-2.4.9/server'
make[1]: *** [all-recursive] 错误 1
make[1]: Leaving directory `/software/httpd-2.4.9/server'
make: *** [all-recursive] 错误 1

5、安装apache httpd-2.4.9:
tar -zxvf httpd-2.4.9.tar.gz #解压

#检查
./configure --prefix=/home/apache-249   #指定httpd安装路径
--with-pcre=/usr/local/pcre                                 #指定pcre的路径
--with-apr=/usr/local/apr                                   #指定apr的路径
--with-apr-util=/usr/local/apr-util                         #指定apr-util的路径
--enable-so                                                 #支持动态共享模块,如果没有这个模块PHP将无法与apache结合工作
--enable-rewrite                                            #启动rewrite模块
--enable-mods-shared=most                                   #安装大多数模块为动态模块
--enable-mpms-shared=all                                    #支持全部多道处理方式
--with-mpm=event                                            #设置httpd工作模式为event

make && make install  #编译 安装

5.1、启动httpd:
到/home/apache-249/bin/
./apachectl start

提示apr_xxxx_xx没有安装 没有编译什么的,具体忘记截图,请见谅。

[root@localhost bin]# ldd httpd    #使用ldd查看httpd依赖的库
       linux-vdso.so.1 =>  (0x00007fff583fd000)
       libpcre.so.1 => /usr/local/pcre/lib/libpcre.so.1 (0x00002b8d0b300000)
       libaprutil-1.so.0 => /usr/lib64/libaprutil-1.so.0 (0x00002b8d0b51c000)
       libexpat.so.0 => /lib64/libexpat.so.0 (0x0000003804a00000)
       libapr-1.so.0 => /usr/lib64/libapr-1.so.0 (0x00002b8d0b76d000)  #问题就出在这里,系统是x64,而且原本的系统也安装了apr,导致现在连接了旧版本的apr
       libuuid.so.1 => /lib64/libuuid.so.1 (0x0000003807600000)
       librt.so.1 => /lib64/librt.so.1 (0x0000003808200000)
       libcrypt.so.1 => /lib64/libcrypt.so.1 (0x0000003816c00000)
       libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003802e00000)
       libdl.so.2 => /lib64/libdl.so.2 (0x0000003802a00000)
       libc.so.6 => /lib64/libc.so.6 (0x0000003802600000)
       /lib64/ld-linux-x86-64.so.2 (0x0000003802200000)

[root@localhost bin]# ./apachectl -V   #查看httpd的版本 (如果在之前出现提示apr_xxxx_xx没有安装 没有编译什么的,这个命令会出现相同的错误提示)
Server version: Apache/2.4.9 (Unix)
Server built:   Apr 15 2014 19:11:19
Server's Module Magic Number: 20120211:31
Server loaded:  APR 1.2.0, APR-UTIL 1.5.3    #Server loaded:  APR 1.2.0为旧版本的apr
Compiled using: APR 1.5.0, APR-UTIL 1.5.3
Architecture:   64-bit
Server MPM:     event
 threaded:     yes (fixed thread count)
   forked:     yes (variable process count)

解决方法:1、查找libapr-1.so.0这个文件(一般在/usr/local/apr下),复制到/usr/lib64/目录下并覆盖(使用ln软连接也可以)
         2、重新安装apr和apr-util,在编译检查时加上--libdir=/usr/lib64
            ./configure --libdir=/usr/lib64 --prefix=/usr/local/apr
            ./configure --libdir=/usr/lib64 --prefix=/usr/local/apr-util  --with-apr=/usr/local/apr
            添加后,在usr/lib64/目录下查看libapr-1.so.0这个文件会看到已经创建了软连接

            [root@localhost lib64]# ls -lal libapr-1.so*
lrwxrwxrwx 1 root root     17 04-15 19:04 libapr-1.so -> libapr-1.so.0.5.0
lrwxrwxrwx 1 root root     17 04-15 19:04 libapr-1.so.0 -> libapr-1.so.0.5.0
-rwxr-xr-x 1 root root 160944 2011-06-01 libapr-1.so.0.2.7
-rwxr-xr-x 1 root root 771023 04-15 19:04 libapr-1.so.0.5.0

         3、重新安装apache httpd,并把apr和apr-util解压到apache httpd安装文件的srclib目录下,改名为apr和apr-util,
            解压和改名后重新安装apache httpd-2.4.9,编译时把--with-apr=/usr/local/apr  --with-apr-util=/usr/local/apr-util这两句删除,
            修改为--with-included-apr(apr和apr-util解压并改名在httpd的srclib目录下时使用)

以上三种方法使用其中一种可解决apr错误链接并提示apr缺失或没有安装的问题。

6、启动apache httpd
[root@localhost bin]#./apachectl -k start


如启动httpd-2.4.9时出现如下错误:
  AH00548: NameVirtualHost has no effect and will be removed in the next release /home/apache-249/conf/extra/httpd-vhosts.conf:19
意思是 NameVirtualHost 已经无效,所以配置虚拟主机httpd-vhosts.conf时不要设置NameVirtualHost就行了。


如启动httpd-2.4.9后登陆页面出现如下错误:

   You don't have permission to access /.net on this server.

请修改:

<Directory />

   AllowOverride none

#Require all denied    #把这句注析

   Require all granted  #增加这句

</Directory>  


Require all denied

比较常用到的有以下几种

Require all denied

Require all granted

Require host xxx.com

Require ip 192.168.1 192.168.2

Require local

若有设定在 .htaccess 中的也要修改

官方参考文档:http://httpd.apache.org/docs/2.4/mod/mod_authz_core.html


安装时候参看了如下链接:
http://xiaomazi.blog.51cto.com/5891742/1393730
http://blog.sina.com.cn/s/blog_701300bc0101dbi2.html