1、安装apr
# tar xvf apr-1.5.2.tar.gz
# cd apr-1.5.2
# ./configure --prefix=/usr/local/apr && make && make install
2、安装apr-util
# tar xvf apr-util-1.5.4.tar.bz2
# cd apr-util-1.5.4
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr && make && make install
3、安装pcre
# tar xvf pcre-8.37.tar.bz2
# cd pcre-8.37
# ./configure --prefix=/usr/local/pcre && make && make install
4、安装httpd
# tar xvf httpd-2.4.18.tar.bz2
# cd httpd-2.4.18
# ./configure --help #查看编译参数
# ./configure --prefix=/usr/local/apache --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre=/usr/local/pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-mpms-shared=all --with-mpm=event --enable-proxy --enable-proxy-http --enable-proxy-ajp --enable-proxy-balancer --enable-lbmethod-heartbeat --enable-heartbeat --enable-slotmem-shm --enable-slotmem-plain --enable-watchdog
--enable-modules=MODULE-LIST #--enable-modules=most ,大多数模块都会启用
Space-separated list of modules to enable | "all" |
"most" | "few" | "none" | "reallyall"
# tailf /usr/local/apache/logs/error_log
[Thu Feb 04 11:09:45.677198 2016] [lbmethod_heartbeat:notice] [pid 62105:tid 140002822612736] AH02282: No slotmem from mod_heartmonitor
[Thu Feb 04 11:09:45.679312 2016] [mpm_event:notice] [pid 62105:tid 140002822612736] AH00489: Apache/2.4.18 (Unix) configured -- resuming normal operations
[Thu Feb 04 11:09:45.679563 2016] [core:notice] [pid 62105:tid 140002822612736] AH00094: Command line: '/usr/local/apache/bin/httpd'
上面的[lbmethod_heartbeat:notice] [pid 62105:tid 140002822612736] AH02282: No slotmem from mod_heartmonitor的警告暂时不用管,当加了mod-jk配置文件或者mod_proxy配置文件之后会消失
# apachectl stop
7、编写启动脚本,方便开机自启动
#!/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
因为自启动脚本中httpd的pid配置在/var/run/httpd.pid下面,所以还需要修改httpd.conf的配置文件
vim /usr/local/apache/conf/httpd.conf
PidFile "/var/run/httpd.pid"
# apachectl configtest
Syntax OK
# /etc/init.d/httpd start
Starting httpd: [ OK ]
# /etc/init.d/httpd stop
Stopping httpd: [ OK ]