Apache2.4安裝指南及一鍵安裝指令碼 1. 前言本文檔試圖以最簡單方式闡明Apache2.4版本的安裝。Apache採用的是automake編譯方式,包括它所依賴的庫,正因為這種依賴,使用得編譯安裝稍變複雜。2. 依賴庫Apache依賴apr、apr-util和pcre,下載網址為:1) Apr和Apr-util:http://apr.apache.org/。截止2012/12/26,版本分別為:apr-1.4.6.tar.gz和apr-util-1.5.1.tar.gz;2) Pcre:http://pcre.org/(實際下載網址是http://sourceforge.net/projects/pcre/files/pcre/和ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/,建議從sourceforge.net處下載,後一個經常抽風)。截止2012/12/26,版本為:pcre-8.32.tar.gz。3. Apache2.4下載網址http://httpd.apache.org/download.cgi#apache24Apache2.4的原始碼包為:httpd-2.4.3.tar.gz(注意最後一位版本號碼3可能不同)。4. 安裝步驟Apr和Apr-util不用特別去編譯和安裝,隨Apache一起完成,見下面的“安裝Apache”一節。4.1. 安裝Pcre在安裝Apache之前,需要安裝好Pcre,安裝過程完全遵循automake方式,步驟依次如下:1) ./configure --prefix=/usr/local/pcre(註:將Pcre安裝到/usr/local/pcre目錄下)2) make3) make install4.2. 安裝Apache1) 將httpd-2.4.3.tar.gz上傳到編譯目錄下(這裡假設編譯目錄為/tmp/X,也可以為其它任意目錄)2) 進入/tmp/X目錄,解壓源碼包:tar xzf httpd-2.4.3.tar.gz,解壓後會在/tmp/X產生一個httpd-2.4.3目錄,在httpd-2.4.3目錄下還會有個srclib子目錄3) 將Apr和Apr-util源碼包上傳到srclib子目錄4) 進入srclib子目錄,將Apr和Apr-util源碼包解壓,如:tar xzf apr-1.4.6.tar.gz; tar xzf apr-util-1.5.1.tar.gz,注意解壓後產生的Apr和Apr-util目錄是帶版本號碼的5) 重新命名Apr和Apr-util目錄,去掉後面的版本號碼,如:mv apr-1.4.6 apr; mv apr-util-1.5.1 apr-util(這個在官方的指南裡有說明的)6) 進入/tmp/X/httpd-2.4.3目錄,按照automake方式來編譯Apache(注意需要指定Pcre):./configure --prefix=/usr/local/httpd --with-pcre=/usr/local/pcre (註:/usr/local/httpd是Apache的安裝目錄,可根據需要修改)。7) 接下來執行make編譯原始碼8) 編譯成功後,執行make install即可將Apache安裝到/usr/local/httpd 目錄下9) 至此,大功告成!!!5. 修改配置如將Apache安裝在/usr/local/httpd目錄下,則進入/usr/local/httpd/conf目錄,對http.conf按照需要進行修改,常修改的行有:1) Listen 802) DocumentRoot "/usr/local/httpd/htdocs"6. 附1:Apache官方中文文檔首頁http://httpd.apache.org/docs/2.4/7. 附2:一鍵指令碼7.1. 一鍵指令碼前提1) 使用root使用者操作;2) Apr、Apr-util、Pcre和Apache安裝包都放在同一個目錄下,如:~/app # lsapr-1.4.6.tar.gz apr-util-1.5.1.tar.gz httpd-2.4.3.tar.gz pcre-8.32.tar.gz3) 目錄下不要放其它尾碼為.tar.gz的檔案7.2. 一鍵指令碼全文#!/bin/sh# Writed by yijian on 2012/12/26# A key to install apache# Download#which wget#if test $? -ne; then# echo "wget NOT FOUND"#else# wget "http://mirror.bjtu.edu.cn/apache/apr/apr-1.4.6.tar.gz"# wget "http://mirror.bjtu.edu.cn/apache/apr/apr-util-1.5.1.tar.gz"# wget "http://labs.mop.com/apache-mirror/httpd/httpd-2.4.3.tar.gz"# wget "http://nchc.dl.sourceforge.net/project/pcre/pcre/8.32/pcre-8.32.tar.gz"#fi# Get namesapr_tar_gz=`ls |grep -e "apr-[0-9]*\.[0-9]*\.[0-9]*\.tar\.gz"`apr_util_tar_gz=`ls |grep -e "apr-util-[0-9]*\.[0-9]*\.[0-9]*\.tar\.gz"`apr=`basename $apr_tar_gz .tar.gz`apr_util=`basename $apr_util_tar_gz .tar.gz`httpd=`basename httpd-*.tar.gz .tar.gz`pcre=`basename pcre-*.tar.gz .tar.gz`echo $aprecho $apr_utilecho $pcreecho $httpd# unzip filestar xzf $apr.tar.gztar xzf $apr_util.tar.gztar xzf $pcre.tar.gztar xzf $httpd.tar.gz# Dependsmv $apr $httpd/srclib/aprif test $? -ne 0; thenexit 1fimv $apr_util $httpd/srclib/apr-utilif test $? -ne 0; thenexit 1fi# Compile pcrecd $pcre./configure --prefix=/usr/local/pcremakeif test $? -ne 0; thenexit 1fimake installif test $? -ne 0; thenexit 1fi# Compile apachecd ../$httpd./configure --prefix=/usr/local/httpd --with-pcre=/usr/local/pcreif test $? -ne 0; thenexit 1fimakeif test $? -ne 0; thenexit 1fimake installif test $? -ne 0; thenexit 1fi# Congratulationecho "finished"cd /usr/local/httpd/conf