Linux下編譯安裝Apache及模組,linuxapache
Apache是時下最流行的Web伺服器軟體之一,支援多平台,可快速搭建web服務,而且穩定可靠,並可通過簡單的API擴充,就可以整合PHP/Python等語言解譯器。文章這裡講解如何在linux下編譯 Apache,以及如何編譯Apache模組。
linux下編譯Apache下載Apache原始碼,編譯過程如下:
$ wget http://apache.fayea.com//httpd/httpd-2.4.12.tar.gz$ tar -zxf httpd-2.4.12.tar.gz$ cd httpd-2.4.12
$ ./configure --prefix=/usr/local/apache/$ make && make install |
編譯過程中,可能會出現了以下錯誤:
| $ ./configure --prefix=/usr/local/apache/checking for chosen layout... Apachechecking for working mkdir -p... yeschecking for grep that handles long lines and -e... /bin/grepchecking for egrep... /bin/grep -Echecking build system type... x86_64-unknown-linux-gnuchecking host system type... x86_64-unknown-linux-gnuchecking target system type... x86_64-unknown-linux-gnuconfigure:configure: Configuring Apache Portable Runtime library...configure:checking for APR... noconfigure: error: APR not found. Please read the documentation. |
這裡是因為Apache編譯依賴 apr,沒找到 apr 就無法正常安裝。另外,Apache還依賴 apr-util 和 pcre
編譯Apache依賴APR是Apache可移植運行庫,封裝了所有作業系統調用,用來實現Apache內部組件對作業系統資源的使用,提高Apache的可移植性。APR和Apache分離出來,避免Apache開發過程中,還要針對不同的平台做不同處理。apr-util 相當於APR工具集。PCRE是實現正則的perl庫。
編譯和安裝 APR
| $ wget http://archive.apache.org/dist/apr/apr-1.5.2.tar.gz$ tar -zxf apr-1.5.2.tar.gz$ cd apr-1.5.2$ ./configure --prefix=/usr/local/apr $ make && make install |
編譯和安裝 apr-util
| $ wget http://archive.apache.org/dist/apr/apr-util-1.5.3.tar.gz$ tar -zxf apr-util-1.5.3.tar.gz$ cd apr-util-1.5.3$ ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr$ make && make install |
編譯和安裝 pcre
| $ wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.37.tar.gz$ tar -zxf pcre-8.37.tar.gz $ cd pcre-8.37$ ./configure --prefix=/usr/local/pcre$ make && make install |
重新編譯Apache安裝Apache依賴後,編譯時間加多幾個參數,重新編譯Apache
| $ ./configure --prefix=/usr/local/apache/ \--with-apr=/usr/local/apr \--with-apr-util=/usr/local/apr-util \--with-pcre=/usr/local/pcre$ make && make install |
編譯Apache模組這裡以mod_concatx為例,說明如何編譯Apache模組,步驟很簡單。mod_concatx是apache模組,可以用來合并多個js/css,有效提高js/css載入速度
編譯 mod_concatx 模組
| $ wget http://apmod.googlecode.com/svn/trunk/mod_concatx/mod_concatx.c$ ln -s /usr/local/apache/bin/apxs /usr/local/bin/apxs$ apxs -c mod_concatx.c |
編譯並安裝mod_concatx 模組
| $ apxs -iac mod_concatx.c |
這種編譯方式會自動安裝Apache模組,安裝成功後,可以在Apache 模組目錄找到 mod_concatx.so,並且 conf/httpd.conf 配置也會加上 mod_concatx 模組資訊
啟動Apache
| $ /usr/local/apache/bin/httpd -k start |
註:Apache啟動後,以後台服務運行。如果想關閉Apache, 就使用以下命令:
| $ /usr/local/apache/bin/httpd -k stop |
查看已載入的Apache模組
$ /usr/local/apache/bin/httpd -M
Loaded Modules:
core_module (static)
so_module (static)
http_module (static)
mpm_event_module (static)
authn_file_module (shared)
authn_core_module (shared)
authz_host_module (shared)
authz_groupfile_module (shared)
authz_user_module (shared)
authz_core_module (shared)
access_compat_module (shared)
auth_basic_module (shared)
reqtimeout_module (shared)
filter_module (shared)
mime_module (shared)
log_config_module (shared)
env_module (shared)
headers_module (shared)
setenvif_module (shared)
version_module (shared)
unixd_module (shared)
status_module (shared)
autoindex_module (shared)
dir_module (shared)
alias_module (shared)
concatx_module (shared) |
說明mod_concatx已載入!
參考:http://blog.csdn.net/mycwq/article/details/46426261