环境介绍:
系统环境:CentOS6.4
所需软件包:apr-1.5.2.tar.gz、apr-util-1.5.4.tar.gz、httpd-2.2.32.tar.gz
注意:官方网站提示apr/arp-util版本要1.4(含)版本以上。
依赖包:zlib-devel
# yum install zlib-devel
开发环境包组:Development Tools, Server Platform Development
# yum groupinstall "Development Tools" "ServerPlatform Development" -y
1、查询旧版apache包名并卸载。
rpm -q httpd
rpm -e --nodeps httpd-2.2.15-59.el6.centos.x86_64
或使用如下shell脚本批量删除旧版apache软件包
for name in `rpm -qa httpd*`;do rpm -e --nodeps $name;done
2、下载源码包
wget https://mirrors.aliyun.com/apache/apr/apr-1.5.2.tar.gz
wget https://mirrors.aliyun.com/apache/apr/apr-util-1.5.4.tar.gz
wget https://mirrors.aliyun.com/apache/httpd/httpd-2.2.32.tar.gz
3、解压
tar -xvf apr-1.5.2.tar.gz
tar -xf apr-util-1.5.4.tar.gz
tar -xvf httpd-2.2.32.tar.gz
4、编译安装apr-1.5.2
cd apr-1.5.2
./configure --prefix=/usr/local/apr-httpd/
make
make install
5、编译安装apr-util-1.5.4
cd apr-util-1.5.4
./configure --prefix=/usr/local/apr-util-httpd/ --with-apr=/usr/local/apr-httpd/
make
make install
6、编译安装httpd-2.2.32
cd httpd-2.2.32
./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd/ --enable-so --enable-deflate --enable-headers --enable-rewrite --with-mpm=prefork --with-apr=/usr/local/apr-httpd/ —with-apr-util=/usr/local/apr-util-httpd/
--prefix:安装路径;
--sysconfdir:指定配置文件路径;
--enable-so:DSO兼容,DSO=Dynamic Shared Object,动态共享对象,可实现模块动态生效;
--enable-deflate:支持压缩功能;需要zlib-devel包支持;
--enable-headers:提供允许对HTTP请求头的控制;
--enable-rewrite:提供基于URL规则的重写功能;
--with-mpm:设置默认启用的MPM模式,{prefork|worker|event};
--with-apr:apr安装路径;
--with-apr-util:apr-util安装的路径;
make
make install
7、设置二进制命令PATH环境变量
编辑文件/etc/profile.d/NAME.sh,输入export PATH=/PATH/TO/BIN:$PATH
vim /etc/profile.d/httpd.sh
export PATH=/usr/local/apache/bin:$PATH
. /etc/profile.d/httpd.sh
注意:bin路径的放在前面系统在读取配置文件的时候会按照自左向右的顺序读取
8、创建链接头文件
ln -sv /usr/local/apache/include/ /usr/include/httpd
"/usr/include/httpd" -> “/usr/local/apache/include/"
9、设置MANPATH
在/etc/man.config文件中新增MANPATH指令,并指向新的命令手册路径;
vim /etc/man.config
MANPATH /usr/local/apache/man
10、启动httpd-2.2.32服务
apachectl start
11、查看80端口是否被监听
ss -tnl
12、使用浏览器访问测试
Reference:
http://www.cnblogs.com/musenl/p/4420067.html
http://xuding.blog.51cto.com/4890434/1728651
http://httpd.apache.org/docs/2.2/install.html#download
http://www.linuxidc.com/Linux/2017-02/140803.htm