LAMP+NFS之編譯安裝http2.4

  • 源碼包準備:

因爲httpd編譯需要aprapr-til所有一併準備好

http1.png

二、編譯過程

1、編譯apr

[root@www ~]# tar xf apr-1.5.0.tar.bz2
[root@www ~]# cd apr-1.5.0
[root@www apr-1.5.0]# ./configure --prefix=/usr/local/apr                     //指明安裝路徑
[root@www apr-1.5.0]# make
[root@www apr-1.5.0]# make install

2、編譯apr-util

[root@www ~]# tar xf apr-util-1.5.3.tar.bz2
[root@www ~]# cd apr-util-1.5.3
[root@www apr-util-1.5.3]# ./configure --prefix=/usr/local/apr-util--with-apr=/usr/local/apr              //指明安裝路徑和apr路徑
[root@www apr-util-1.5.3]# make
[[email protected]]# make install

3、編譯httpd24

[root@www ~]# tar xf httpd-2.4.10.tar.bz2
[root@www ~]# cd httpd-2.4.10
[root@www httpd-2.4.10]# ./configure --prefix=/usr/local/httpd24--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
--prefix=/usr/local/httpd24指明安裝路徑
--sysconfdir=/etc/httpd24指明配置文件路徑
--enable-so支持模塊動態裝卸載
--enable-ssl支持ssl加密
--enable-cgi支持cgi
--enable-rewrite支持重寫
--with-zlib支持zlib壓縮
--with-apr=/usr/local/apr指明apr路徑
--with-apr-util=/usr/local/apr-util/指明apr-util路徑
--enable-modules=most用most可以將一些不常用的,不在缺省常用模塊中的模塊編譯進來.
--with-mpm=event工作模式
[root@www httpd-2.4.10]# make
[root@www httpd-2.4.10]# make install

注意:編譯的時候如果出錯,查看錯誤信息,如果提示缺少某包,直接用安裝該包的devel包,編譯完成不要忘記makemake install

  • httpd配置

修改配置文件添加pid路徑

http2.png

在配置文件的任意位置添加PidFile /var/run/httpd.pid,如上圖所示

httpd提供服務啓動腳本

創建文件/etc/rc.d/init.d/httpd24並添加如下代碼

#!/bin/bash
#chkconfig: 345 85 15
#
#httpd        Startup script for theApache HTTP Server
#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
 
# Sourcefunction library.
. /etc/rc.d/init.d/functions
 
if [ -f/etc/sysconfig/httpd ]; then
        . /etc/sysconfig/httpd
fi
 
# Starthttpd in the C locale by default.
HTTPD_LANG=${HTTPD_LANG-"C"}
 
# Thiswill prevent initlog from swallowing up a pass-phrase prompt if
# mod_sslneeds a pass-phrase from the user.
INITLOG_ARGS=""
 
# SetHTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
# withthe thread-based "worker" MPM; BE WARNED that some modules may not
# workcorrectly with a thread-based MPM; notably PHP will refuse to start.
 
# Path tothe apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/httpd24/bin/apachectl
httpd=${HTTPD-/usr/local/httpd24/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 toconfiguration syntax error"
        failure $"not reloading $httpd dueto configuration syntax error"
    else
        killproc -p ${pidfile} $httpd -HUP
        RETVAL=$?
    fi
    echo
}
 
# See howwe were called.
case "$1" in
  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@www httpd-2.4.10]# chmod +x/etc/rc.d/init.d/httpd24

chkconfig檢查,支持chkconfig,但是沒有加入,使用命令chkconfig–add httpd24

[root@www httpd-2.4.10]# chkconfig --listhttpd24
service httpd24 supports chkconfig, but isnot referenced in any runlevel (run 'chkconfig --add httpd24')
[root@www httpd-2.4.10]# chkconfig –addhttpd24

現在就可以使用service httpd24 start啓動httpd服務了

http3.png

啓動成功,檢查端口

http4.png

80端口已經監聽,我們去物理機的瀏覽器測試

http5.png

現在http服務器已經可以工作了。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章