# 安装apr
[root@a ~]# tar -xzf apr-1.5.2.tar.gz
[root@a ~]# cd apr-1.5.2
# 选择安装路径为/usr/local/apr
[root@a apr-1.5.2]# ./configure --prefix=/usr/local/apr
[root@a apr-1.5.2]# make && make install
# 安装apr-util
[root@a ~]# tar -xzf apr-util-1.5.4.tar.gz
[root@a ~]# cd apr-util-1.5.4
# 选择安装路径为/usr/local/apr-util,并解决apr包依赖
[root@a apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@a apr-util-1.5.4]# make && make install
# 安装pcre
[root@a ~]# tar -xzf pcre-8.32.tar.gz
[root@a ~]# cd pcre-8.32
[root@a pcre-8.32]# ./configure --prefix=/usr/local/pcre
[root@a pcre-8.32]# make && make install
现在我们就可以编译安装httpd包了,过程如下:
[root@a ~]# tar -xzf httpd-2.4.23.tar.gz
[root@a ~]# cd httpd-2.4.23
# 安装路径为/usr/local/apache;apr、apr-util依赖路径分别如下;
# --sysconfdir=/etc/httpd表示配置文件路径为/etc/httpd目录
[root@a httpd-2.4.23]# ./configure --prefix=/usr/local/apache \
--enable-so --enable-rewirte --enable-ssl --enable-cgi --enable-cgid \
--enable-modules=most --enable-mods-shared=most --enable-mpms-shared=all \
--with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util \
--sysconfdir=/etc/httpd --with-pcre=/usr/local/pcre
[root@a httpd-2.4.23]# make && make install
如果没什么问题的话,Apache就安装完成了。启动服务来测试一下吧
# 我们知道httpd服务的端口为80,保险起见,我们先来看一下是否已经有本地httpd服务正在运行
[root@a ~]# netstat -tunlp | grep 80
# 如果80端口没有被占用,我们可以执行如下命令启动httpd服务
[root@a ~]# /usr/local/apache/bin/apachectl start
# 可能会出现如下信息: 原因是我们没有为httpd服务设置ServerName
AH00557: httpd: apr_sockaddr_info_get() failed for a
AH00558: httpd: Could not reliably determine the server's fully qualified domain name,
using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
# 编辑配置文件/etc/httpd/http.conf,将ServerName前的注释# 去掉即可,重启服务,进行测试
# 修改/etc/httpd/httpd.conf配置文件,在最后添加如下内容:
PidFile "/var/run/httpd.pid"
# 新建/etc/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