hjqjk 標籤: httpd2.4 編譯安裝 CentOS6.5linux
1、當前環境;apache
系統和內核版本:vim
系統的httpd版本:bash
2、在CentOS6.5中編譯安裝httpd2.4網絡
一、準備環境dom
安裝httpd前需準備的程序包組;這幾個程序包系統自帶光盤就有,只需掛載到指定目錄,製做成本地yum源便可安裝使用。(此處不作過多介紹)ide
解決依賴關係:工具
[root@localhost ~]# yum groupinstall -y "Server Platform Development" [root@localhost ~]# yum groupinstall -y "Development tools" [root@localhost ~]# yum install -y pcre-devel-7.8-6.el6.x86_64二、編譯安裝httpd2.4及httpd2.4所依賴的軟件包開發工具
若是CentOS6.5系統中httpd服務已經啓動了,先中止httpd服務測試
[root@localhost ~]# service httpd stop
(1)簡單介紹
CentOS7默認安裝httpd2.4。
CentOS6用的是httpd2.2,CentOS6中默認的庫和開發工具不支持使用httpd2.4。想要在CentOS6中安裝httpd2.4,就要更新更高版本的apr和apr-util。
APR(Apache portable Run-time libraries,Apache可移植運行庫)的目的如其名稱同樣,主要爲上層的應用程序提供一個能夠跨越多操做系統平臺使用的底層支持接口庫。它是個可以讓Apache跨平臺工做的工具,是個底層庫,安裝上apr後。若是在win和linux上安裝上apr後,Apache的同一個代碼,便可以在win上運行也可在linux上運行;
當前CentOS6.5的apr版本:
httpd2.4依賴於更高版本的apr和apr-util(要是1.4或1.4以上的版本)。
(2)下載最新版的httpd、apr和apr-util
[root@localhost ~]# wget http://apache.fayea.com/apache-mirror//httpd/httpd-2.4.9.tar.bz2
[root@localhost ~]# wget http://mirrors.hust.edu.cn/apache//apr/apr-1.5.0.tar.gz
[root@localhost ~]# wget http://mirrors.hust.edu.cn/apache//apr/apr-util-1.5.3.tar.gz
(3)編譯安裝apr-1.5.0
[root@localhost ~]# tar xf apr-1.5.0.tar.bz2 [root@localhost ~]# cd apr-1.5.0 [root@localhost apr-1.5.0]# ./configure --prefix=/usr/local/apr [root@localhost apr-1.5.0]# make && make install基於編譯安裝,會把全部的環境和開發工具裝上,不一樣於rpm有子包的概念。
(4)編譯安裝apr-util-1.5.3
[root@localhost ~]# tar xf apr-util-1.5.3.tar.bz2 [root@localhost ~]# cd apr-util-1.5.3 [root@localhost apr-util-1.5.3]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr [root@localhost apr-util-1.5.3]# make && make install由於apr-util-1.5.3是做爲apr-1.5.0的工具使用的,因此要用--with-apr選項指定apr的安裝目錄。
(5)編譯安裝httpd-2.4.9
[root@localhost ~]# tar xf httpd-2.4.9.tar.bz2 [root@localhost ~]# cd httpd-2.4.9 [root@localhost httpd-2.4.9]# ./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-mpms-shared=all --with-mpm=event --enable-modules=most [root@localhost httpd-2.4.9]# make && make install
選項解釋:
--prefix=/usr/local/apache 安裝路徑
--sysconfdir=/etc/httpd24 配置文件路徑
--enable-so 容許運行時加載DSO模塊
--enable-ssl 若是不加載將沒法使用使用https
--enable-cgi 容許使用cgi腳本
--enable-rewrite 支持URL重寫機制
--with-zlib 支持網絡通用壓縮庫
--with-pcre 支持pcre
--with-apr=/usr/local/apr 指定apr的安裝路徑
--with-apr-util=/usr/local/apr-util/ 指定apr-util的安裝路徑
--enable-mpms-shared=all 啓用MPM全部支持的模式
--with-mpm=event 默認使用enevt模式
--enable-modules=most 啓用大多數經常使用的模塊
查看安裝後所生成的文件,extra目錄是2.4版新增目錄
三、編譯後所需的配置
(1)導出二進制程序
[root@localhost ~]# vim /etc/profile.d/httpd24.sh [root@localhost ~]# cat /etc/profile.d/httpd24.sh export PATH=/usr/local/apache/bin:$PATH [root@localhost ~]# source /etc/profile.d/httpd24.sh [root@localhost ~]# echo $PATH /usr/local/apache/bin:/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin [root@localhost ~]# httpd -v Server version: Apache/2.4.9 (Unix) Server built: Aug 9 2014 06:00:59(2)啓動httpd服務並測試是否已經導出二進制程序
[root@localhost ~]# apachectl start測試是否成功導出二進制程序:
(注意:httpd2.4是使用apachectl命令來啓動服務的。)
測試成功!
(3)導出頭文件;以目錄連接的形式來實現
[root@localhost ~]# ln -sv /usr/local/apache/include /usr/include/httpd24 `/usr/include/httpd24' -> `/usr/local/apache/include'注意:能夠把一個目錄連接到一個文件中
(頭文件主要是用於二次開發)
(4)導出man文件
[root@localhost ~]# vim /etc/man.config在/etc/man.config配置文件中添加以下代碼:
MANPATH /usr/local/apache/man
測試是否成功:
[root@localhost ~]# man -M /usr/local/apache/man httpd [root@localhost ~]# man httpd(5)提供httpd服務腳本
[root@localhost ~]# vim /etc/rc.d/init.d/httpd24修改服務配置文件,先把httpd服務中止
[root@localhost init.d]# apachectl stop httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName httpd (no pid file) not running
腳本以下:
#!/bin/bash # # httpd Startup script for the Apache HTTP Server # # chkconfig: - 85 15 # description: The Apache HTTP Server is an efficient and extensible \ # server implementing the current HTTP standards. # processname: httpd # config: /etc/httpd/conf/httpd.conf # config: /etc/sysconfig/httpd # pidfile: /var/run/httpd/httpd.pid # ### BEGIN INIT INFO # Provides: httpd # Required-Start: $local_fs $remote_fs $network $named # Required-Stop: $local_fs $remote_fs $network # Should-Start: distcache # Short-Description: start and stop Apache HTTP Server # Description: The Apache HTTP Server is an extensible server # implementing the current HTTP standards. ### END INIT INFO # 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 #指定新的apachectl腳本的位置httpd=${HTTPD-/usr/local/apache/bin/httpd} #指定新的httpd程序的位置 prog=httpd pidfile=${PIDFILE-/usr/local/apache/logs/httpd.pid} #指定新的httpd服務的進程文件lockfile=${LOCKFILE-/var/lock/subsys/httpd} RETVAL=0 STOP_TIMEOUT=${STOP_TIMEOUT-10} # The semantics of these two functions differ from the way apachectl does # things -- attempting to start while running is a failure, and shutdown # when not running is also a failure. So we just do it the way init scripts # are expected to behave here. start() { echo -n $"Starting $prog: " LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS RETVAL=$? echo [ $RETVAL = 0 ] && touch ${lockfile}return $RETVAL } # When stopping httpd, a delay (of default 10 second) is required # before SIGKILLing the httpd parent; this gives enough time for the # httpd parent to SIGKILL any errant children. stop() { echo -n $"Stopping $prog: " killproc -p ${pidfile} -d ${STOP_TIMEOUT} $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=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 } # See how we were called.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測試:
[root@localhost ~]# chkconfig --add httpd24 [root@localhost ~]# chkconfig --list httpd24 httpd24 0:off 1:off 2:off 3:off 4:off 5:off 6:off [root@localhost ~]# service httpd24 start Starting httpd: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message [ OK ] [root@localhost ~]# service httpd24 stop Stopping httpd: [ OK ]測試成功!