安装环境
- 系统环境:CentOS 6.5-x86_64
- 所需软件包:
- apr-1.5.0.tar.bz2
- apr-util-1.5.3.tar.bz2
- httpd-2.4.9.tar.bz2
- 下载地址:
安装步骤
- 注:httpd-2.4版本依赖于更高版本(1.5版本以上)的apr和apr-util;apr全称为apache portable
runtime,能实现httpd跨平台运行 - 解决依赖关系
tar xf apr-util-1.5.3.tar.bz2
cd apr-util-1.5.3
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/
make && make install - 编译安装apr-1.5.0
tar xf apr-1.5.0.tar.bz2
cd apr-1.5.0
./configure --prefix=/usr/local/apr
make && make install - 编译安装apr-util-1.5.3
tar xf apr-util-1.5.3.tar.bz2
cd apr-util-1.5.3
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/
make && make install - httpd编译安装
tar xf httpd-2.4.9.tar.bz2
cd httpd-2.4.9
./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd249 --enable-so --enable-ssl --enable-cgi --enable-rewrite --enable-deflate --with-z --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enable-modules=most --enable-mpms-shared=all --with-mpm=event
make && make install
# 各编译参数详解
--prefix:#安装路径
--sysconfdir:#指定配置文件路径
--enable-so:#DSO兼容,DSO=Dynamic Shared Object,动态共享对象,可实现模块动态生效
--enable-ssl:#支持SSL/TLS,可以实现https访问
--enable-cgi:#支持CGI脚本(默认对非线程的MPM模式开启)
--enable-rewrite:#启用Rewrite功能
--enable-deflate:#支持压缩
--with-z:#使用指定的zlib库,不指定路径会自动寻找
--with-pcre:#使用指定的PCRE库,不指定路径会自动寻找
--with-apr:#指定apr安装路径
--with-apr-util:#指定apr-util安装路径
--enable-modules:#支持动态启用的模块,可选参数有“all”,“most”,“few”,“reallyall”
--enable-mpms-shared:#支持动态加载的MPM模块,可选“all”
--with-mpm:#设置默认启用的MPM模式
后续配置
i.修改httpd的主配置文件,设置其Pid文件的路径
ln -sv /usr/local/apache/include /usr/include/httpd
ii.导出头文件
ln -sv /usr/local/apache/include /usr/include/httpd
iii.导出man手册
vi /etc/man.config
MANPATH /usr/local/apache/man # man文件在apache安装目录下哦
iv.编写服务脚本(因是编译安装,不会自动生成服务脚本)
# vi /etc/rc.d/init.d/httpd
#!/bin/bash
#
# httpd Startup script for the Apache HTTP Server
#
# chkconfig: - 85 15
# description: Apache is a World Wide Web server. It is used to serve # HTML files and CGI.
# processname: httpd
# config: /etc/httpd/conf/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /var/run/httpd.pid
# Source function library.
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/httpd ]; then
. /etc/sysconfig/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=""
# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
# with the thread-based "worker" MPM; BE WARNED that some modules may not
# work correctly with a thread-based MPM; notably PHP will refuse to start.
# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/apache/bin/apachectl
httpd=${HTTPD-/usr/local/apache/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/var/run/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0
start() {
echo -n $"Starting $prog: "
LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch ${lockfile}
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc -p ${pidfile} -d 10 $httpd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
reload() {
echo -n $"Reloading $prog: "
if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
RETVAL=$?
echo $"not reloading due to configuration syntax error"
failure $"not reloading $httpd due to configuration syntax error"
else
killproc -p ${pidfile} $httpd -HUP
RETVAL=$?
fi
echo
}
# See how we were called.
case "$1" in
start)
start;;
stop)
stop;;
status)
status -p ${pidfile} $httpd
RETVAL=$?;;
restart)
stop
start;;
condrestart)
if [ -f ${pidfile} ] ; then
stop
start
fi;;
reload)
reload;;
graceful|help|configtest|fullstatus)
$apachectl [email protected]
RETVAL=$?;;
*)
echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
exit 1
esac
exit $RETVAL
启动服务并测试
# 为服务脚本赋予执行权限:
chmod +x /etc/rc.d/init.d/httpd
# 加入服务列表:
chkconfig --add httpd
# 启动服务
service httpd start
浏览器访问:http://Server_IP/ # 显示“It works”,即表示httpd服务启动成功
httpd 2.4新特性说明
- 新增特性
- MPM支持在运行时装载
- 支持event MPM类型
- 支持异步读写
- 在每模块及每目录上指定日志级别
- 每请求配置:<If>,<Elseif>
- 增强版的表达式分析器
- 毫秒级的keepalive timeout
- 基于FQDN的虚拟主机不再需要NameVirtualHost指令
- 支持使用自定义变量
- 新增模块
- mod_proxy_fcgi
- mod_ratelimit
- mod_request
- mod_remoteip
- 修改
- 对于基于IP的访问控制做了修改,不再支持使用order, allow,
deny这些机制,而是统一使用require进行
- 对于基于IP的访问控制做了修改,不再支持使用order, allow,
时间: 2024-10-16 04:23:11