CentOS 6.5 编译安装Apache2.4
一、 httpd 2.4的新特
1) MPM支持运行时装载
--enable-mpms-shared=all --with-mpm=prefork|worker|event
2) 支持event MPM
3) 异步读写支持
4) 支持每模块及每目录分别使用不同的日志级别
5) 支持per-request(即支持<If>, <ElseIf>, and <Else>条件判断)
6) 增强版的表达式分析器;
7) 支持毫秒级keepalive timeout;
8) 基于FQDN(域名)的虚拟主机不再需要NameVirtualHost;
9) 支持用户使用自定义变量;
新增一些模块:mod_proxy_fcgi, mod_ratelimit, mod_request, mod_remoteip
修改了一些配置机制:不再支持使用order, allow, deny来实现基于IP的访问控制;
二、 系统环境
CentOS6.4 x86_64位 采用最小化安装,系统经过了基本优化 1G内存,1核cpu
selinux为关闭状态,iptables关闭状态
三、编译准备
1. 安装相关依赖工具
# yum install -y gcc gcc-c++ wget expat-devel zlib-devel zlib openssl openssl-devel libxml2-devel
2. 下载相关软件包
# wget http://www-us.apache.org/dist//httpd/httpd-2.4.37.tar.gz
# wget -c http://www-us.apache.org/dist//apr/apr-1.6.5.tar.gz
# wget -c http://www-us.apache.org/dist//apr/apr-util-1.6.1.tar.gz
# wget https://ftp.pcre.org/pub/pcre/pcre-8.32.tar.gz
3. 编译安装依赖包
# cd /usr/local/src
安装apr:
# tar xf apr-1.6.5.tar.gz
# cd apr-1.6.5
# ./configure --prefix=/usr/local/apr
# make && make install
安装apr-util:
# tar xf apr-util-1.6.1.tar.gz
# cd apr-util-1.6.1
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
# make && make install
安装pcre:
# tar -xf pcre-8.32.tar.gz
# cd pcre-8.32
# ./configure --prefix=/usr/local/pcre
# make && make install
注意:如果你下载pcre2的话,apache2.4会出现编译不通过,建议不要使用pcre2.
四、编译安装httpd
# tar -xf httpd-2.4.37.tar.gz
# cd httpd-2.4.37
开始配置:
./configure \
--prefix=/usr/local/httpd24 \
--sysconfdir=/etc/httpd24 \
--enable-so \
--enable-ssl \
--enable-cgi \
--enable-rewrite \
--with-zlib \
--enable-deflate \
--enable-expires \
--with-pcre=/usr/local/pcre \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util \
--enable-mods-shared=most \
--enable-mpms-shared=all \
--with-mpm=prefork/event/worker注意:如果是复制粘贴配置,要注意每行结尾\之前只能有一个空格,之后不能有空格
参数含义:
./configure \
--prefix=/usr/local/httpd24 \ # 指定安装路径
--sysconfdir=/etc/httpd24 \ # 指定配置文件路径
--enable-so \ # 启用动态模块加载
--enable-ssl \ # 启用ssl加密传输
--enable-cgi \ # 允许使用cgi脚本
--enable-rewrite \ # 启用url重写功能
--with-zlib \ # 支持数据包压缩
--enable-deflate \ # 支持网页压缩
--enable-expires \ # 支持网页缓存
--with-pcre=/usr/local/pcre \ # pcre安装路径
--with-apr=/usr/local/apr \ # apr安装路径
--with-apr-util=/usr/local/apr-util \ # apr-util 安装路径
--enable-mods-shared=most \ # 动态的编译进来大多数的模块
--enable-mpms-shared=all \ # 动态编译MPM所有支持的模式
--with-mpm=prefork/event/worker # 默认加载使用的mpm编译并安装:
# make && make install
五、安装后配置
1. 将apache二进制程序目录加入环境变量PATH
# echo 'export PATH=/usr/local/http24/bin:$PATH' >>/etc/profile
# source /etc/profile
2. 链接方式输出头文件
# ln -sv /usr/local/httpd24/include /usr/include/apache
3. 添加man帮助手册
编辑man.config文件,找到 MANPATH /usr/X11R6/man 这一行,在下面添加如下一行
MANPATH /usr/local/httpd24/man
4.添加启动脚本
a. 系统自带脚本
# cp /usr/local/httpd24/bin/apachectl /etc/init.d/httpd
vi打开,添加两行
# chkconfig: 35 85 15
# description: The Apache HTTP Serverb. 相关启动脚本
#!/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/httpd.conf
# pidfile: /usr/local/httpd24/logs/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/httpd ]; then
. /etc/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=""
# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/httpd24/bin/apachectl
httpd=/usr/local/httpd24/bin/httpd
prog=httpd
pidfile=${PIDFILE-/usr/local/httpd24/logs/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd24}
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() {
status -p ${pidfile} $httpd > /dev/null
if [[ $? = 0 ]]; then
echo -n $"Stopping $prog: "
killproc -p ${pidfile} -d ${STOP_TIMEOUT} $httpd
else
echo -n $"Stopping $prog: "
success
fi
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
c. 开机启动httpd服务
# chkconfig --add httpd
# chkconfig httpd on
# chkconfig --list httpd
5. 测试安装
打开浏览器,在浏览器输入centos主机的ip地址,或者本机curl,检测安装是否成功。
# curl localhost
<html><body><h1>It works!</h1></body></html>
六、可能遇到的问题
1. 启动报错
启动时会出现“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”这样的报错,只需要编辑http.conf文件,找到#ServerName www.example.com:80这一行,在下面添加 如下一行,然后重启apache
# vim /etc/httpd/httpd.conf
ServerName localhost:80
取消以下注释行,开启httpd状态监控
Include /etc/httpd24/extra/httpd-info.conf
2.

参数方面没问题,然后我开始一个个去掉参数:发现问题出现在--enable-cgi \这个上面,故这个有问题。
最后对调参数,参数放在倒数第二个再次环境测试!结果发现通过了!,其实问题出现在\后面有空格,去掉空格再编译
3. 
这个提示是openssh版本太低,yum install -y openssl openssl-devel 解决
4.

缺少了xml相关的库,需要安装libxml2-devel包。直接安装并不能解决问题,因为httpd调用的apr-util已经安装好了,但是apr-util并没有libxml2-devel包支持。
安装libxml2-devel包
[root@localhost ~]# yum install -y libxml2-devel
删除apr-util安装目录,并重新编译安装
[root@localhost ~]# rm -rf /usr/local/apr-util
[root@localhost ~]# cd /usr/local/src/apr-util-1.6.1
# 这一步很重要,必须清除之前配置时的缓存
[root@localhost apr-util-1.6.1]# make clean
# 源码安装三步走
[root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@localhost apr-util-1.6.1]# make
[root@localhost apr-util-1.6.1]# make install
重新编译安装httpd
# 同样要清理之前的缓存十分重要
[root@localhost src]# cd /usr/local/src/httpd-2.4.28
[root@localhost httpd-2.4.28]# make clean
[root@localhost httpd-2.4.28]# ./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most
[root@localhost httpd-2.4.28]# make
# 这时make没报错了
[root@localhost httpd-2.4.28]# make install
注:此处参考http://blog.51cto.com/castiel/2051440
CentOS 6.5 编译安装Apache2.4的更多相关文章
- CentOS6.3 编译安装LAMP(2):编译安装 Apache2.2.25
所需源码包: /usr/local/src/Apache-2.2.25/httpd-2.2.25.tar.gz 编译安装 Apache2.2.25 #切换到源码目录 cd /usr/local/src ...
- CentOS6.3 编译安装LAMP(2):编译安装 Apache2.4.6
Apache官方说: 与Apache 2.2.x相比,Apache 2.4.x提供了很多性能方面的提升,包括支持更大流量.更好地支持云计算.利用更少的内存处理更多的并发等.除此之外,还包括性能提升.内 ...
- centos6.3编译安装Apache2.4.3+PHP5.4.8+Mysql5.5.8
以虚拟机VirtualBox 版本是4.1.20(内存设置为512M,centos安装是文本模式下安装),全新以最小化包安装了32位的 CentOS6.3系统,作为本地web环境,上次讲了在windo ...
- CentOS 6.8编译安装httpd2.2.31+MySQL5.6.31+PHP5.3.27
CentOS 6.8编译安装httpd2.2.31+MySQL5.6.31+PHP5.3.27 说明: 操作系统:CentOS 6.8 32位 准备篇: 一.系统约定 软件源代码包存放位 ...
- Ubuntu 16.04下编译安装Apache2.4和PHP7结合
Ubuntu 16.04下编译安装Apache2.4和PHP7结合,并安装PDOmysql扩展. 1.编译安装apache2.4.20 1 第一步: ./configure --prefix=/usr ...
- CentOS 7.0编译安装Nginx1.6.0+MySQL5.6.19+PHP5.5.14
准备篇: CentOS 7.0系统安装配置图解教程 http://www.osyunwei.com/archives/7829.html 一.配置防火墙,开启80端口.3306端口 CentOS 7. ...
- centos 7.0 编译安装php 7.0.3
php下载页面 http://cn2.php.net/downloads.php 7.0.3多地区下载页面 http://cn2.php.net/get/php-7.0.3.tar.gz/from/a ...
- CentOS 6.6编译安装Nginx1.6.2+MySQL5.6.21+PHP5.6.3
http://www.osyunwei.com/archives/8867.html 一.配置防火墙,开启80端口.3306端口 vi /etc/sysconfig/iptables #编辑防火墙配置 ...
- CentOS 6.2编译安装Nginx1.2.0+MySQL5.5.25+PHP5.3.13
CentOS 6.2编译安装Nginx1.2.0+MySQL5.5.25+PHP5.3.132013-10-24 15:31:12标签:服务器 防火墙 file 配置文件 written 一.配置好I ...
随机推荐
- MATLAB中产生高斯白噪声的两个函数
MATLAB中产生高斯白噪声非常方便,可以直接应用两个函数,一个是WGN,另一个是AWGN.WGN用于产生高斯白噪声,AWGN则用于在某一信号中加入高斯白噪声.1.WGN:产生高斯白噪声 y = wg ...
- Linux磁盘分区与lvm逻辑卷
硬盘接口的种类分四类:(价格由低到高) IDE SATA硬盘:别名串口硬盘,具有较强的纠错能力. SCSI硬盘:即采用SCSI接口的硬盘,SCSI接口具有应用范围广,多任务,带宽大,CPU占用率低. ...
- CenterNet
Objects as Points anchor-free系列的目标检测算法,只检测目标中心位置,无需采用NMS 1.主干网络 采用Hourglass Networks [1](还有resnet18 ...
- Problem 1538 - B - Stones II 贪心+DP
还是给你石头n枚,每一枚石头有两个值a和b,每取一个石头,除了这块石头其余所有的石头的a就都减去这个石头的b,问你取了的石头的a的总和最大可以为多少? 先按B从大到小排序 然后DP: 取的话:dp[i ...
- __name__='main' 这句代码是什么意思?《读书笔记》
当我们阅读 别人的python代码都会有 if name == "main"这么一行语句,但却不知道为什么要写这个?有什么用 想知道这段代码什么意思让我们来根据例子来测试一下 我们 ...
- event loop 与 vue
结论 对于event loop 可以抽象成一段简单的代码表示 for (macroTask of macroTaskQueue) { // 1. Handle current MACRO-TASK h ...
- thinkPHP模型定义
批量新增 ArrayAccess类的属性当做数组访问 插入语句 这段代码说明,User继承的Model类的isupdate属性默认是isupdate,而User::get(1)把这一字段属性更新为tr ...
- Quartz--Spring 定时任务
一.quartz核心概念 先来看一张图: scheduler 任务调度器 trigger 触发器,用于定义任务调度时间规则 job 任务,即被调度的任务 misfire 错过的,指本来应该被 ...
- JMeter 功能挖掘之 WEB 文件导出
前言 自从写从0构建自动化测试平台(一)之技术选型开始,在工作中Get新技能就非常想郑重的记录下来,方便自己查阅:相信很多人都有这种感触:平时问题解决后,没有及时记录,下次遇到类似问题,需要花同等的成 ...
- 【NOIP2016提高A组模拟8.19】(雅礼联考day2)公约数
题目 给定一个正整数,在[1,n]的范围内,求出有多少个无序数对(a,b)满足gcd(a,b)=a xor b. 分析 显然a=b是一定不满足, 我们设\(a>b\), 易得gcd(a,b)&l ...