Centos6.2安裝Apache2.4步驟詳解

來源:互聯網
上載者:User

apache2.4安裝方法一

下面寫了我今天的安裝記錄。系統: Centos6.2 X64  httpd 2.4.1

1.下載包,wget http://apache.etoak.com//httpd/httpd-2.4.1.tar.bz2
2.解壓, tar xjf httpd-2.4.1.tar.bz2
3.安裝編譯環境 yum -y install gcc gcc-c++ glibc glibc-common pcre-devel flex autoconf make automake
4.下載apr, wget http://labs.mop.com/apache-mirror//apr/apr-1.4.6.tar.bz2
5.下載apr-util,  wget http://mirror.bit.edu.cn/apache//apr/apr-util-1.4.1.tar.bz2
6.解壓apr,tar xjf apr-1.4.6.tar.bz2
7.解壓apr-util,tar xjf apr-util-1.4.1.tar.bz2
8.編譯 apr, cd apr-1.4.6   ./configure --prefix=/usr/local/apr    make && make install
9.編譯apr-util, cd ../apr-util-1.4.   ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config   make && make install
10.cd httpd-2.4.1
11../configure --prefix=/usr/local/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enable-so --enable-modules=all
12. make && make install
13./usr/local/apache/bin/apachectl start


設定Apache自動啟動

Apache安裝路徑為:/usr/local/apache
 1)、cp  /usr/local/apache/bin/apachectl  /etc/rc.d/init.d/httpd  //如果有其他的版本的Apache存在,也可以直接覆蓋掉。
ln  -s  /etc/rc.d/init.d/httpd  /etc/rc.d/rc5.d/S85httpd      //建立連結
此時Apache就可以自動啟動了。


2)、運行chkconfig --list,發現沒有linux服務列表中httpd,通過chkconfig --add httpd來添加,但是提示:httpd服務不支援 chkconfig。需要編輯/etc/rc.d/init.d/httpd,添加以下注釋資訊:


#chkconfig: 345 85 15
#description: Apache

第一行3個數字參數意義分別為:哪些Linux層級需要啟動httpd(3,4,5);啟動序號(85);關閉序號(15)。
儲存後執行:chkconfig --add httpd,成功添加。
s
在rc3.d、rc4.d、rc5.d路徑中會出現S85httpd的連結檔案,其他運行層級路徑中會出現K61httpd的連結檔案。


apache 安裝方法二


 依賴庫
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#apache24

Apache2.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) make

3) make install

4.2. 安裝Apache
1) 將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 80

2) 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 # ls

apr-1.4.6.tar.gz  apr-util-1.5.1.tar.gz  httpd-2.4.3.tar.gz  pcre-8.32.tar.gz

3) 目錄下不要放其它尾碼為.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 names

apr_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 $apr

echo $apr_util

echo $pcre

echo $httpd
# unzip files

tar xzf $apr.tar.gz

tar xzf $apr_util.tar.gz

tar xzf $pcre.tar.gz

tar xzf $httpd.tar.gz
# Depends

mv $apr $httpd/srclib/apr

if test $? -ne 0; then

exit 1

fi

mv $apr_util $httpd/srclib/apr-util

if test $? -ne 0; then

exit 1

fi
# Compile pcre

cd $pcre

./configure –prefix=/usr/local/pcre

make

if test $? -ne 0; then

exit 1

fi

make install

if test $? -ne 0; then

exit 1

fi
# Compile apache

cd ../$httpd

./configure –prefix=/usr/local/httpd –with-pcre=/usr/local/pcre

if test $? -ne 0; then

exit 1

fi

make

if test $? -ne 0; then

exit 1

fi

make install

if test $? -ne 0; then

exit 1

fi
# Congratulation

echo “finished”

cd /usr/local/httpd/conf

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.