天天看點

linux源碼下載下傳阿帕奇,Ubuntu 12.04下源碼安裝Apache

環境:Ubuntu 12.04

【簡單安裝】

一般第一次安裝Apache都較為順利。

1. 下載下傳并解壓

[email protected]:/home/qy/share#tar zxvf httpd-2.2.22.tar.gz

[email protected]:/home/qy/share#cd httpd-2.2.22

在http-2.2.22裡有檔案README和INSTALL,用more指令可以閱讀。

2. 配置

[email protected]:/home/qy/share/httpd-2.2.22#./configure --prefix=/usr/local/apache

--prefix參數指定了将要安裝到的目錄。此時/usr/local下還沒有該目錄,make install後才會出現。

注意:Apache在安裝時不會檢查參數是否正确,錯誤的參數會直接被丢棄,不會報告給使用者。是以使用echo $?指令檢查是否有錯誤,當輸出結果為0時表示沒有錯誤。

3. 編譯

[email protected]:/home/qy/share/httpd-2.2.22#make

4. 安裝

[email protected]:/home/qy/share/httpd-2.2.22#make install

5. 啟動伺服器

[email protected]:/home/qy/share/httpd-2.2.22#cd /usr/local/apache/bin

[email protected]:/usr/local/apache/bin#./apachectl start

為了以後使用友善,可以把啟動檔案apachectl複制到/sbin下,以後直接apachectl start啟動。

#vi /etc/rc.local

增加一行 /sbin/apachectl start

6. 驗證Apache是否工作

此時,伺服器端視窗應該顯示:

linux源碼下載下傳阿帕奇,Ubuntu 12.04下源碼安裝Apache

#ps -e|grep httpd

linux源碼下載下傳阿帕奇,Ubuntu 12.04下源碼安裝Apache

在用戶端浏覽器輸入伺服器的IP位址(或者http://localhost),IE應該顯示:It works!畫面。

Ubuntu重新開機後,需要重新開機Apache: apachectl start

停止伺服器:  ./apachectl stop

重新開機伺服器:  ./apachectl graceful  或   ./apachectl restarted

通常,第一次安裝Apache沒有什麼問題,但以後安裝,如果沒有apr,apr-util,pcre,在執行./configure的配置過程中可能遇到的錯誤:

make[2]: *** [install] Error 1

make[2]: Leaving directory `/tmp/httpd-2.2.22/srclib/apr-util'

make[1]: *** [install-recursive] Error 1

make[1]: Leaving directory `/tmp/httpd-2.2.22/srclib'

make: *** [install-recursive] Error 1

Apache2.0.x與Apache2.2.x在apr上有本質的差別,前者為依賴公用apr,後者依賴于自身的apr。2.0.x的編譯基本上沒有apr方面的問題,除非,在編譯前,安裝了非2.0.x所需的apr,如果是這樣,則需要将已經安裝的apr去除,然後再編譯。HTTP Sever2.2.22修複了不少重要安全問題,包含APR(Apache Portable Runtime)1.4.5和APR-util(Apache Utility Library)1.4.2。是以不需要像網上其它教程那樣從外部找源碼安裝apr和apr-util。将安裝前已存在于系統中的apr去除後,再編譯apache2.2.x自身srclib裡的apr和apr-util。其它作業系統這樣解決就沒問題了,但是Ubuntu不太一樣。安裝完apr和apr-util後,./configure配置Apache時可能會出現下面錯誤:

configure: error: Cannot use an external APR with the bundled APR-util

configure: error: APR version 1.2.0 or later is required

srclib目錄中有apr,apr-util,pcre三個源碼包,其中pcre是不可用的,編譯不出來,有如下錯誤:

libtool: compile: unrecognized option `-DHAVE_CONFIG_H'

libtool: compile: Try `libtool --help' for more information.

make: *** [pcrecpp.lo] Error 1

ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/上下載下傳的pcre-8.30也不可用。不妨用make check指令檢視下錯誤出在什麼地方。一般懷疑是g++版本低,更新即可。我沒有這樣做,而是直接用apt-get install libpcre3-dev安裝了pcre後,再安裝apache就沒問題了。

linux源碼下載下傳阿帕奇,Ubuntu 12.04下源碼安裝Apache