Apache + PHP 有三種安裝模式:靜態模組、動態模組 (DSO) 與 CGI。DSO 模式維護彈性最高:需新增功能 (如加密、資料庫驅動) 時,只需 make clean → 重新 configure 加入選項 → make → make install → 重啟 Apache,完全無需重新編譯 Apache 本體。
/usr/local/ 或 /opt/。gunzip 解壓 → tar -xvf apache_[version].tar。/usr/local/apache_[version]。./configure --prefix=[安裝路徑] --enable-module=so (啟用 DSO 支援)。make → make install。tar -xvf php-[version] → 進入 /usr/local/php-[version]。./configure --with-mysql=/[mysql路徑] --with-apxs=/[apxs路徑]apxs 位於 Apache bin/ 目錄,是編譯 DSO 關鍵工具。make → make install。編譯器會產生 libphp4.so 放入 Apache 模組目錄,並自動修改 httpd.conf。# 1. 管理員信箱
ServerAdmin you@yourdomain.com
# 2. 伺服器名稱
ServerName localhost
# 3. PHP 型別對應 (取消註解並加入副檔名)
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps
./bin/apachectl start。htdocs/) 建立 phpinfo.php:<? phpinfo() ?>https://localhost/phpinfo.php,應顯示完整 PHP 資訊頁。需調整 PHP 編譯選項時:make clean → 新 configure 參數 → make → make install → 重啟 Apache 載入新模組。過往須重編 Apache 的痛苦至此終結。