Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學

Linux 從原始碼編譯安裝 APR、APR-util 與 Apache HTTPD 完整教學

編輯:Linux 系統常見問題解答

前置準備

從 Apache 官網下載以下三個原始碼套件:

  • APR: apr-1.3.2.tar.gz
  • APR-util: apr-util-1.3.2.tar.gz
  • HTTPD: httpd-2.2.9.tar.gz (從 官網下載頁 取得)

第一步:安裝 APR

tar zxvf apr-1.3.2.tar.gz
cd apr-1.3.2
./configure
make
make install
# 預設安裝至 /usr/local/apr

第二步:安裝 APR-util (指定 APR 路徑)

tar zxvf apr-util-1.3.2.tar.gz
cd apr-util-1.3.2
./configure --with-apr=/usr/local/apr
make
make install

關鍵參數:--with-apr=/usr/local/apr 指定剛安裝好的 APR 路徑,否則 configure 會找不到 APR。

第三步:編譯安裝 Apache HTTPD

tar zxvf httpd-2.2.9.tar.gz
cd httpd-2.2.9
./configure \
  --prefix=/usr/local/apache2 \
  --enable-so \
  --enable-rewrite \
  --enable-auth-digest \
  --enable-cgi \
  --enable-suexec \
  --with-suexec-caller=daemon \
  --with-suexec-docroot=/usr/local/apache2/htdocs
make
make install

常用 configure 參數說明

參數用途
--prefix安裝根目錄
--enable-so支援動態載入模組 (DSO)
--enable-rewrite啟用 mod_rewrite (URL 重寫)
--enable-suexec啟用 suEXEC 安全機制
--with-suexec-caller指定允許呼叫 suexec 的使用者

驗證安裝

/usr/local/apache2/bin/apachectl start
# 瀏覽器訪問 https://localhost/ 應顯示 "It works!"

注意事項

  • 編譯前請確認已安裝 gcc、make、libpcre、openssl-devel 等開發套件。
  • APR 版本需與 HTTPD 版本相容,建議參考官網建議搭配。
  • 生產環境建議使用套件管理器 (apt/yum) 安裝以利後續安全性更新。
Copyright © Windows教程網 All Rights Reserved