在CentOS6.10上手动编译安装httpd2.4.46时遇到的问题(使用了最新的apr1.7.0和apr-util1.6.1):
报错信息:
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
解决方法:
[root@lotus httpd-2.4.46]# yum install -y pcre-devel
报错信息:
checking whether to enable mod_ssl... configure: error: mod_ssl has been requested but can not be built due to prerequisite failures
解决方法:
[root@lotus httpd-2.4.46]# yum install openssl-devel -y
报错信息:
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_ParserCreate'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_GetErrorCode'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetUserData'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_ErrorString'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetEntityDeclHandler'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_ParserFree'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetElementHandler'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_StopParser'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_Parse'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetCharacterDataHandler'
解决方法:
将apr-util版本从1.6.1降低至1.5.3后,httpd编译安装正常
下载路径:apr-util
编译安装httpd
- 安装pcre-devel
- 如开启了openssl-devel,则需安装openssl-devel包【yum install openssl-devel -y】
- 编译安装apr
- 编译安装apr-util
- 编译安装httpd
- 下载软件
[root@lotus ~]# wget https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.7.0.tar.gz
--2021-04-06 16:30:49-- https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.7.0.tar.gz
Resolving mirrors.tuna.tsinghua.edu.cn... 101.6.8.193, 2402:f000:1:408:8100::1
Connecting to mirrors.tuna.tsinghua.edu.cn|101.6.8.193|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1093896 (1.0M) [application/octet-stream]
Saving to: “apr-1.7.0.tar.gz”
100%[======================================================================================>] 1,093,896 6.47M/s in 0.2s
2021-04-06 16:30:49 (6.47 MB/s) - “apr-1.7.0.tar.gz” saved [1093896/1093896]
[root@lotus ~]# wget https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
--2021-04-06 16:31:05-- https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
Resolving mirrors.tuna.tsinghua.edu.cn... 101.6.8.193, 2402:f000:1:408:8100::1
Connecting to mirrors.tuna.tsinghua.edu.cn|101.6.8.193|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 554301 (541K) [application/octet-stream]
Saving to: “apr-util-1.6.1.tar.gz”
100%[======================================================================================>] 554,301 --.-K/s in 0.1s
2021-04-06 16:31:05 (4.37 MB/s) - “apr-util-1.6.1.tar.gz” saved [554301/554301]
[root@lotus ~]# wget https://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.46.tar.gz
--2021-04-06 16:31:53-- https://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.46.tar.gz
Resolving mirrors.tuna.tsinghua.edu.cn... 101.6.8.193, 2402:f000:1:408:8100::1
Connecting to mirrors.tuna.tsinghua.edu.cn|101.6.8.193|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9363314 (8.9M) [application/octet-stream]
Saving to: “httpd-2.4.46.tar.gz”
100%[======================================================================================>] 9,363,314 10.1M/s in 0.9s
2021-04-06 16:31:54 (10.1 MB/s) - “httpd-2.4.46.tar.gz” saved [9363314/9363314]
#将软件时间同步为硬件时间
[root@lotus ~]# hwclock -s
[root@lotus ~]# date
Mon Apr 12 16:35:49 CST 2021
- 解压安装apr和apr-util
#解压
[root@lotus apr-1.7.0]# tar xf apr-1.7.0.tar.gz
#进入apr-1.7.0目录,进行编译
[root@lotus apr-1.7.0]# cd apr-1.7.0
#因apr安装centos时已经安装,为避免覆盖造成其它程序依赖出现问题,安装时指定与源apr不同的安装路径
[root@lotus apr-1.7.0]# ./configure --prefix=/usr/local/apr
[root@lotus apr-1.7.0]# make && make install
#解压安装apr-utils,apr-util依赖于apr
[root@lotus ~]# tar xf apr-util-1.6.1.tar.gz
[root@lotus ~]# cd apr-util-1.6.1
[root@lotus apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@lotus apr-util-1.6.1]# make && make install
- 编译安装httpd
# --sysconfdir:设定httpd配置文件目录
# --enable-so:支持动态加载模块
# --enable-rewrite:支持URL重写
# --enable-ssl:支持ssl
# -- enable-cgi:支持cgi
# --enable-cgid:使用一个外部 CGI 守护进程执行CGI脚本
# --enable-mods-shared:most,all,few(默认为most,即动态编译大多数模块)
# --enable-mpms-shared:支持大多数mpm(prefork,event,worker)
# --with-apr:关联的apr
# --with-apr-util:关联的apr-util
[root@lotus httpd-2.4.46]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-rewrite --enable-ssl --enable-cgi --enable-cgid --enable-module=most --enable-mods-shared=most --enable-mpms-shared=all --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util
[root@lotus httpd-2.4.46]# make && make install
#启动之前一定要关闭selinux
[root@lotus httpd-2.4.46]# vim /etc/selinux/config
SELINUX=disabled
#先关闭httpd服务器,修改httpd.pid文件的存放位置,由于编译安装时指定了httpd的配置文件放入/etc/httpd目录下,到/etc/httpd目录下找到httpd.conf文件,添加一行PidFile /var/run/httpd.pid
#启动httpd,到httpd的安装目录,执行启动命令
[root@lotus apache]# bin/apachectl start
- 在/etc/init.d/目录编写一个httpd的脚本,实现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 file and CGI.
# processname: httpd
# config: /etc/httpd/conf/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /var/run/httpd.pid
# 载入函数库
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/httpd ];then
. /etc/sysconfig/httpd
fi
#设定HTTPD_LANG为C
HTTPD_LANG=${HTTPD_LANG="C"}
#This will prevent initlog from swallowing up a pass-parase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARG=""
apachectl=/usr/local/apache/bin/apachectl
#如HTTPD为空,则设定httpd为/usr/local/apche/bin/httpd
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
}
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 $@
RETVAL=$?
;;
*)
echo $"Usage:$prog (start|stop|restart|reload|configtest|status|hep)"
exit 1
esac
exit $RETVAL
- httpd的新特性
- MPM可运行时加载
- Event MPM
- 异步读写
- 每个模块及每个目录上指定日志级别
- 请求配置,,
- 增强的表达式分析器
- 毫秒级的KeepAlive Timeout
- 基于域名的虚拟主机不再需要NameVirtualHost指令
- 降低了内存占用
- 支持在配置文件中使用自定义变量
- 新增加的模块
- mod_proxy_fcgi
- mod_proxy_scgi
- mod_proxy_exress
- mod_remoteip
- mod_session
- mod_ratelimit
- mod_request等