以下以 Linux 的 Debian 為安裝 apache 的示範平台



以現在很方便使用的線上套件升級程式,RedHat派系為 yum ,Debian 為 apt等等,要安裝套件以經非常簡便,底下示範這兩支程式安裝 apache 的方法:

yum
yum install httpd

apt
apt-get install apache

這樣系統就會幫你把 apache 給裝好。但是,有時我們可能需要依照自己的環境,量身訂造自己的 apache,如果使用線上套件升級程式可能沒辦法做到,這時就必須使用自行編譯的方式來建置自己的 apache。

文件參考: http://httpd.apache.org/docs/2.2/install.html
Apache 版本:2.2


安裝步驟總覽

下載       $ lynx http://httpd.apache.org/download.cgi
解壓縮    $ gzip -d httpd-NN.tar.gz
設置      $ ./configure --prefix=PREFIX
編譯      $ make
安裝      $ make install
在地化    $ vi PREFIX/conf/httpd.conf
修改      $ PREFIX/bin/apachectl -k start

與一般使用編譯的安裝方式差不多。文中的 httpd-NN ,NN 代表目前的最新版本。PREFIX 代表你要安裝的路徑,不指定的話為 /usr/local/apache2。


安裝需求

硬碟空間
至少 50MB 的安裝空間,另外依未來你會新增的第三方程式或是網站成長的速度去評估所需的硬碟空間。

編譯器
使用編譯的方式安裝,當然少不了編譯器,常用的首推 GNU C compiler(GCC)。安裝方式可使用 yum 或 apt 安裝 gcc 即可。

apr
一般這個套件會綑在 apache 的 source 一起發行,如果你系統上以經有安裝 apr 的話,請記得更新版本。另外,如果系統上未安裝 apr ,要使用 source 的 apr 來安裝,請參考下面的說明。(安裝 apr 之前,請先安裝 autoconf 與 libtool 這兩個套件,不然可能會無法安裝)

apr 安裝示範
 # 強制使用 tar file 裡的 apr
./configure --with-included-apr

To build Apache HTTPd against a manually installed apr/apr-util:
# Build and install apr 1.2
cd srclib/apr
./configure --prefix=/usr/local/apr-httpd/
make
make install

# Build and install apr-util 1.2
cd ../apr-util
./configure --prefix=/usr/local/apr-util-httpd/ --with-apr=/usr/local/apr-httpd/
make
make install

# Configure httpd,這時安裝 apache 的時候,就要指定 apr 與 apr-util 的路徑
cd ../../
./configure --with-apr=/usr/local/apr-httpd/ --with-apr-util=/usr/local/apr-util-httpd/



下載 apache
http://httpd.apache.org/download.cgi 這個網站下載 apache 的 source ,這裡選擇的是 httpd-2.2.11.tar.bz2

解壓縮
下載回來的 source 都是打包或是壓縮過的,因此要先將檔案解開,你可以使用底下這兩種方式:
 gzip -d httpd-NN.tar.gz
 tar xvf httpd-NN.tar


編譯
接著就是執行 ./configure 來進行編譯,編譯的時候可以修改許多安裝參數,你可以連到 http://httpd.apache.org/docs/2.2/programs/configure.html#installationdirectories 來看有哪些參數可以修改。

安裝
執行 make install

客製化
 PREFIX/conf/httpd.conf 這個是 apache 的主要設定檔,你可以再裡面依你的需求做修改,修改完請重新啟動 apache。

測試
現在你可以起動你的 Apache HTTP Server了,使用 PREFIX/bin/apachectl -k start 來起動 apache。


arrow
arrow
    全站熱搜

    xiangyang17 發表在 痞客邦 留言(0) 人氣()