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 ...
随机推荐
- hier - 文件系统描述
DESCRIPTION 描述 一个典型的Linux系统具有以下几个目录: / 根目录,是所有目录树开始的地方. /bin 此目录下包括了单用户方式及系统启动或修复所用到的所有执行程序. /boot 包 ...
- kill - 终止进程
SYNOPSIS(总览) kill[-ssignal|-p][-a]pid... kill -l [ signal ] DESCRIPTION (描述) kill 给指定进程发送指定信号. 如果没有指 ...
- nginx.conf laravel 配置
server { listen 443; server_name www.liuhuanguang.cn; #填写绑定证书的域名 ssl on; ssl_certificate cert/1_www. ...
- 通过lua扩展nginx
1. 安装 准备主要的三个安装包,分别是 nginx-1.15.9.tar.gz LuaJIT-2.0.5.tar.gz lua-nginx-module-0.10.14.tar.gz 相关版本可以去 ...
- squid之------基础知识
squid是什么? 缓存服务器,即用来存储(内存及硬盘)用户访问的网页.图片.文件等等信息的专用服务器,这种服务器不仅可以使用户最快的得到他们想要的信息,而且大大减少了网络传输的数据量,缓存服务器经常 ...
- redis主从+keepalived实现高可用技术
Redis是我们当下比较流行使用的非关系数据库,可支持多样化的数据类型,多线程高并发支持,redis运行在内存拥有更快的读写.因为redis的表现如此出色,如何能保障redis在运行中能够应对宕机故障 ...
- layui 中的$符号有可以和jquery冲突,var & = layui.$
在项目上使用到了滚动条插件,但是使用var & = layui.$,会影响到插件. 错误提示: Uncaught TypeError: $(...).perfectScrollbar is n ...
- VSCode编辑器用户设置
{"gitlens.advanced.messages": {"suppressCommitHasNoPreviousCommitWarning": false ...
- ASP.NET实现文件断点续传
IE的自带下载功能中没有断点续传功能,要实现断点续传功能,需要用到HTTP协议中鲜为人知的几个响应头和请求头. 一. 两个必要响应头Accept-Ranges.ETag 客户端每次提交下载请求时,服务 ...
- tensorflow的变量作用域
一.由来 深度学习中需要使用大量的变量集,以往写代码我们只需要做全局限量就可以了,但在tensorflow中,这样做既不方便管理变量集,有不便于封装,因此tensorflow提供了一种变量管理方法:变 ...