1. 程式人生 > >編譯安裝httpd-2.4

編譯安裝httpd-2.4

most should apache服務 -a rpm包 開始 mil ice table

首先要準備好環境,然後下載httpd-2.4.25.tar的包(http://httpd.apache.org)

1:安裝包組

# yum groupinstall -y "Development tools" "Server Platform Development"

2:安裝依賴包

# yum install -y pcre-devel apr-devel apr-util-devel openssl-devel

3:解壓本地的httpd-2.4.25.tar

# tar xf httpd-2.4.25.tar

# cd httpd-2.4.25

4:配置安裝信息,生成make file,yum安裝的rpm包一般都是在/usr目錄下

# ./configure --prefix=/usr/local/apache-2.4 --sysconfdir=/etc/httpd-2.4 --enable-so --enable-ssl --enable-rewrite --enable-modules=most --enable-mpms-shared=all --with-zlib --with-pcre --with-apr=/usr --with-apr-util=/usr --with-mpm=prefork

5:編譯安裝

# make && make install

6:制作鏈接,便於版本管控

# ln -sv /usr/local/apache-2.4 /usr/local/apache

7:因為自帶的Apache服務控制腳本:Apachectl 腳本在/usr/local/apache-2.4/bin/目錄下,可以將這個目錄加到環境變量中,編輯vi /etc/profile.d/httpd.sh ,添加export PATA=/usr/local/apache/bin/:$PATH,那麽啟動的時候就可以直接使用apachectl start

# vi /etc/profile.d/httpd.sh

export PATA=/usr/local/apache/bin/:$PATH

# ./etc/profile.d/httpd.sh

8:將頭文件和庫文件輸出到默認的

# ln -sv /usr/apache/include /usr/include/httpd

9:啟動httpd-2.4

# apachectl start

10:編寫服務腳本實現 server httpd start 啟動httpd(從這裏開始一下都可可以不用寫)

# vi /etc/rc.d/init.d/functions

#! /bin/bash
#
# network Bring up/down networking
#
# chkconfig: 2345 10 90
# description: Activates/Deactivates all network interfaces configured to \
# start at boot time.
#
### BEGIN INIT INFO
# Provides: $network
# Should-Start: iptables ip6tables NetworkManager-wait-online NetworkManager $network-pre
# Short-Description: Bring up/down networking
# Description: Bring up/down networking
### END INIT INFO

# Source function library.

. /etc/rc.d/init.d/functions

if [ -f /etc/sysconfig/httpd ]; then
. /etc/sysconfig/httpd
fi

HTTPD_LANG=${HTTPD_LANG-"C"}

INITLOG_ARGS=""


apachectl=/usr/local/apache/bin/apachectl
httpd=${HTTPD-/usr/local/apache/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/usr/local/apache/logs/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0
STOP_TIMEOUT=${STOP_TIMEOUT-10}

start() {
echo -n $"Starting $prog: "
LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch ${lockfile}
return $RETVAL
}

stop() {
status -p ${pidfile} $httpd > /dev/null
if [[ $? = 0 ]]; then
echo -n $"Stopping $prog: "
killproc -p ${pidfile} -d ${STOP_TIMEOUT} $httpd
else
echo -n $"Stopping $prog: "
success
fi
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}

reload() {
echo -n $"Reloading $prog: "
if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
RETVAL=6
echo $"not reloading due to configuration syntax error"
failure $"not reloading $httpd due to configuration syntax error"
else
# Force LSB behaviour from killproc
LSB=1 killproc -p ${pidfile} $httpd -HUP
RETVAL=$?
if [ $RETVAL -eq 7 ]; then
failure $"httpd shutdown"
fi
fi
echo
}

case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p ${pidfile} $httpd
RETVAL=$?
;;
restart)
stop
start
;;
condrestart|try-restart)
if status -p ${pidfile} $httpd >&/dev/null; then
stop
start
fi
;;
force-reload|reload)
reload
;;
graceful|help|configtest|fullstatus)
$apachectl $@
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}"
RETVAL=2
esac

exit $RETVAL

11:讓腳本可以被chkconfig管控

# chkconfig --add /etc/rc.d/init.d/httpd-2.4

12:使用service重啟服務

# service httpd-2.4 restart

編譯安裝httpd-2.4