1.)首先到apache官方网站 http://httpd.apache.org/download.cgi 下载最新版本的apache,本文的版本是httpd-2.4.3.tar.bz2(截至2015-6-4,官网最新版本httpd-2.4.12依然适用本文档)。解压安装,执行如下命令:
./configure --prefix=/opt/httpd --enable-so
若出现下面的错误提示
configure: error: APR not found. Please read the documentation.
说明缺少apr包,到apache官网下载http://apr.apache.org/download.cgi。
2)安装apr很简单,默认路径就可以
./configure;make;make install
默认安装到了/usr/local/apr,安装完成后,把apr的lib库路径放到系统库环境变量可以找到的位置,编剧/etc/ld.so.conf文件,添加/usr/local/apr/lib,保存后执行ldconfig使之生效。
注意:若系统提示错误“rm: cannot remove `libtoolT': No such file or directory”,解决办法可能是系统中的automake没有正确安装,使用yum install automake* 安装后就没问题了。这一点很多人找不到原因,我这里给出办法或许可以帮助你们。
APR介绍:APR(Apache portable Run-time libraries,Apache可移植运行库),其功能主要为上层的应用程序提供一个可以跨越多操作系统平台使用的底层支持接口库。
3)继续回来编译apache,执行 ./configure --prefix=/opt/httpd --enable-so
出现这个错误提示 configure: error: APR-util not found. Please read the documentation。这个错误说明缺少apr-util软件包。
4)下载编译apr-util之后,安装apr-util
./configure --with-apr=/usr/local/apr
make;make install
5)继续安装apache,提示下面的错误
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/,说明缺少pcre软件包,从http://sourceforge.net/projects/pcre/ 下载并编译安装
./configure --prefix=/usr/local/pcre;make;make install
PCRE介绍:(Perl Compatible Regular Expressions 即 Perl语言兼容的正则表达式)是一个用C语言编写的正则表达式函数库,由菲利普.海泽(Philip Hazel)编写。PCRE是一个轻量级的函数库,比Boost之类的正则表达式库小得多。PCRE十分易用,同时功能也很强大,性能超过了POSIX正则表达式库和一些经典的正则表达式库
6)继续安装apache,
./configure --prefix=/opt/httpd --enable-so
接下来很顺利的编译通过。apache安装全部完成。
注意:若系统中存在多个版本的apr,且安装默认找到的版本较旧,可以使用参数--with-apr=/usr/local/apr来明确用新版本的apr。
最后,给出 httpd-2.4.12的编译命令
指明使用apr,apr-util,pcre,mpm工作模式的编译命令如下:
./configure --prefix=/opt/httpd2.4.12 --with-mpm=worker --with-apr=/usr/local/apr --with-pcre=/usr/local/pcre --with-apr-util=/usr/local/apr-util