Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

CentOS 編譯安裝 Apache HTTPD 2.4 完整教程:APR/APR-Util/PCRE 依賴鏈、configure 參數、目錄佈局

編輯:Linux 教學

前置依賴安裝

yum install -y gcc gcc-c++ make expat-devel pcre-devel openssl-devel

1. APR (Apache Portable Runtime)

wget https://dlcdn.apache.org/apr/apr-1.7.4.tar.gz
tar -zxf apr-1.7.4.tar.gz && cd apr-1.7.4
./configure --prefix=/usr/local/apr
make && make install

2. APR-Util

wget https://dlcdn.apache.org/apr/apr-util-1.6.3.tar.gz
tar -zxf apr-util-1.6.3.tar.gz && cd apr-util-1.6.3
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config
make && make install

3. PCRE (Perl Compatible Regular Expressions)

wget https://sourceforge.net/projects/pcre/files/pcre/8.45/pcre-8.45.tar.gz
tar -zxf pcre-8.45.tar.gz && cd pcre-8.45
./configure --prefix=/usr/local/pcre
make && make install

4. Apache HTTPD 2.4 編譯安裝

wget https://dlcdn.apache.org/httpd/httpd-2.4.62.tar.gz
tar -zxf httpd-2.4.62.tar.gz && cd httpd-2.4.62
./configure \
  --prefix=/usr/local/apache2 \
  --with-apr=/usr/local/apr \
  --with-apr-util=/usr/local/apr-util \
  --with-pcre=/usr/local/pcre \
  --enable-so \
  --enable-ssl \
  --enable-rewrite \
  --enable-mods-shared=most
make && make install

關鍵 configure 參數說明

安裝後驗證與管理

# 檢查版本與編譯參數
/usr/local/apache2/bin/httpd -V

# 啟動/停止/重啟
/usr/local/apache2/bin/apachectl start
/usr/local/apache2/bin/apachectl stop
/usr/local/apache2/bin/apachectl restart

# 設定開機自啟 (systemd)
cat > /etc/systemd/system/httpd.service <<'EOF'
[Unit]
Description=Apache HTTP Server
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/apache2/bin/apachectl start
ExecStop=/usr/local/apache2/bin/apachectl stop
ExecReload=/usr/local/apache2/bin/apachectl graceful
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable httpd
systemctl start httpd

目錄佈局概覽

/usr/local/apache2/
├── bin/           # httpd, apachectl, ab, htdigest ...
├── conf/          # httpd.conf, mime.types, extra/
├── logs/          # access_log, error_log
├── modules/       # mod_*.so
└── htdocs/        # 預設網站根目錄
Copyright © Windows教程網 All Rights Reserved
參數作用
--prefix安裝根目錄
--with-apr/apr-util/pcre指定依賴安裝路徑
--enable-so啟用 DSO 動態模組載入 (必須)
--enable-ssl編譯 mod_ssl (HTTPS)
--enable-rewrite編譯 mod_rewrite (URL 重寫)
--enable-mods-shared=most大多數模組編譯為共享 .so