httpd-2.4 以上版本需要较新版本的apr和apr-util,因此需要事先对其进行升级。升级方式有两种,一种是通过源代码编译安装,一种是直接升级rpm包。这里通过源代码编译安装进行全部演示。官方下载地址:http://httpd.apache.org/
编译安装apr-1.5.0
[root@ch tmp]# tar xf apr-1.5.0.tar.bz2
[root@ch tmp]# cd apr-1.5.0
[root@ch apr-1.5.0]# ./configure --prefix=/usr/local/apr
[root@ch apr-1.5.0]# make -j 4 && make install
编译安装apr-util-1.5.2
[root@ch tmp]# tar xf apr-util-1.5.2.tar.bz2
[root@ch tmp]# cd apr-util-1.5.2
[root@ch apr-util-1.5.2]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@ch apr-util-1.5.2]# make -j 4 && make install
编译安装http-2.4.6
[root@ch httpd-2.4.6]# yum -y install pcre-devel
[root@ch tmp]# tar xf httpd-2.4.6.tar.bz2
[root@ch tmp]# cd httpd-2.4.6
[root@ch httpd-2.4.6]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-fcgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mpms-shared=all --enable-mpm=worker
[root@ch httpd-2.4.6]# make -j 4 && make install
-enable-so 支持动态模块机制
-enable-ssl 支持ssl功能
-enable-fcgi -enable-rewrite 支持fcgi和url重写
-enable-modules=all 启用大多数常用模块
-enable-mpms-shared=all 编译prefork/worker/event 3个模块
-with-mpm-worker 设置默认模块为worker
-with-zlib 支持压缩
-with-pcre 支持pre扩展的正则表达式引擎
修改httpd的主配置文件,设置其Pid文件的路径
[root@ch tmp]# vim /etc/httpd/httpd.confPidFile "/var/run/httpd.pid" ## 在配置文件中添加这一行即可
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so ## 启用fcgi模块
提供SysV服务脚本
[root@ch tmp]# vim /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 $@
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
exit 1
esac
exit $RETVAL
[root@ch tmp]# chmod +x /etc/rc.d/init.d/httpd ## 赋予脚本执行权限
[root@ch tmp]# chkconfig --add httpd ## 加入服务列表
[root@ch tmp]# service httpd start ## 启动httpd服务
[root@ch tmp]# netstat -tan ## 查看80端口是否监听
至于库文件、man文档、系统命令、头文件依旧按照编译安装mariadb 第5节配置即可
[root@ch httpd]# vim httpd.conf ## 编辑主配置文件
<Location /server-status>
SetHandler server-status
Require ip 172.18.20.1 ## 仅允许172.18.20.1 主机查看
</Location>
