centos6 編譯安裝httdp2.4
httpd-2.4需要較新版本的apr和apr-util,因此需要事先對其進行升級。升級方式有兩種,一種是通過源代碼編譯安裝,一種是直接升級rpm包。
這裏選擇使用編譯源代碼的方式進行
1、解決依賴關系
yum groupinstall -y "Development Tools" "Server Platform Development"
yum install -y pcre-devel
下載軟件包
apr-1.5.0.tar.bz2
apr-util-1.5.3.tar.bz2
httpd-2.4.25.tar.bz2
(1) 編譯安裝apr
編譯安裝 apr
解壓並進入目錄
./configure --prefix=/usr/local/apr
make && make install
(2) 編譯安裝apr-util
解壓進入目錄
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr 需要指定apr路徑
(3)編譯安裝httpd2.4
./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --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 --with-mpm=event
make && make install
補充:
(1)構建MPM為靜態模塊
在全部平臺中,MPM都可以構建為靜態模塊。在構建時選擇一種MPM,鏈接到服務器中。如果要改變MPM,必須重新構建。為了使用指定的MPM,請在執行configure腳本 時,使用參數 --with-mpm=NAME。
NAME是指定的MPM名稱。編譯完成後,可以使用 ./httpd -l 來確定選擇的MPM。 此命令會列出編譯到服務器程序中的所有模塊,包括 MPM。
(2)構建 MPM 為動態模塊
在Unix或類似平臺中,MPM可以構建為動態模塊,與其它動態模塊一樣在運行時加載。 構建 MPM 為動態模塊允許通過修改LoadModule指令內容來改變MPM,而不用重新構建服務器程序。
在執行configure腳本時,使用--enable-mpms-shared選項即可啟用此特性。當給出的參數為all時,所有此平臺支持的MPM模塊都會被安裝。
還可以在參數中給出模塊列表。默認MPM,可以自動選擇或者在執行configure腳本時通過--with-mpm選項來指定,然後出現在生成的服務器配置文件中。編輯LoadModule指令內容可以選擇不同的MPM。
3、修改httpd的主配置文件,設置其Pid文件的路徑
編輯/etc/httpd/httpd.conf,添加如下行即可:
PidFile "/var/run/httpd.pid"
4、提供SysV服務腳本/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 [email protected]
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
exit 1
esac
exit $RETVAL
而後為此腳本賦予執行權限:
# chmod +x /etc/rc.d/init.d/httpd
加入服務列表:
# chkconfig --add httpd
接下來就可以啟動服務進行測試了。
[[email protected]Linux bin]# service httpd restart
AH00557: httpd: apr_sockaddr_info_get() failed for linux.64.114
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
解決方法
[[email protected] httpd24]# pwd
/etc/httpd24
[[email protected] httpd24]# vim httpd.conf
修改ServerName www.example.com:80 為 ServerName localhost:80
3、繼續執行checking whether to enable mod_ssl... configure: error: mod_ssl has been requested but can not be built due to prerequisite failures,這是因為缺少openssl
[[email protected] httpd-2.4.18]# yum install openssl-devel
4、最後出現的一個報錯是configure: error: MPM most does not support dynamic loading.
從字面上可以了解,此時將--enbale-mpm-shared改為all即可
centos6 編譯安裝httdp2.4