萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 程式設計 >  >> 網路程式設計 >> PHP 程式設計

PHP 編譯安裝常用配置參數參考 (PHP 4.3.11 / 4.4.0)

說明

本文記錄兩個歷史 PHP 版本的典型編譯配置參數,僅供遺留項目維護或版本演進研究參考。現代項目請使用 PHP 8.x 並參考官方文檔配置。

PHP 4.3.11 配置示例

./configure \
--prefix=/home/raid/system/php \
--with-mysql=/home/raid/system/mysql/ \
--with-apxs=/home/raid/system/apache/bin/apxs \
--with-gd \
--with-zlib \
--with-freetype-dir=/usr/ \
--with-png-dir=/usr/ \
--with-jpeg-dir=/usr/ \
--disable-posix \
--enable-memory-limit \
--enable-zend-multibyte \
--with-iconv \
--enable-inline-optimization \
--enable-magic-quotes \
--enable-ftp

關鍵參數說明

參數作用
--prefix安裝根目錄
--with-mysql指定 MySQL 安裝路徑(使用舊版 mysql 客戶端庫)
--with-apxs啟用 Apache 2.0 模塊支持 (apxs 路徑)
--with-gd啟用 GD 圖形庫
--with-freetype-dir --with-png-dir --with-jpeg-dir指定 FreeType、PNG、JPEG 庫路徑,GD 依賴
--disable-posix禁用 POSIX 函數(精簡)
--enable-memory-limit啟用腳本內存限制 (memory_limit)
--enable-zend-multibyte啟用 Zend 多字節支持(PHP 5.4+ 移除,改用 mbstring)
--with-iconv啟用字符集轉換
--enable-inline-optimization啟用內聯優化(GCC)
--enable-magic-quotes啟用魔術引號(PHP 5.4+ 已移除,極不推薦)
--enable-ftp啟用 FTP 支持

PHP 4.4.0 配置示例

./configure \
--prefix=/usr/local/php \
--with-apxs=/usr/local/apache/bin/apxs \
--with-iconv=/usr/local \
--enable-mbstring \
--with-gd \
--with-jpeg-dir=/usr/local \
--with-png-dir=/usr/local \
--with-freetype-dir=/usr/local \
--with-ttf \
--enable-gd-native-ttf \
--with-zlib-dir=/usr \
--with-dom=/usr/local \
--with-mysql=/usr/local \
--with-ldap=/usr/local \
--with-curl=/usr/local

新增/變化參數

  • --enable-mbstring:多字節字符串支持(替代 zend-multibyte)。
  • --with-ttf --enable-gd-native-ttf:FreeType 2 支持 TrueType 字體。
  • --with-dom:DOM XML 支持(PHP 5 內建)。
  • --with-ldap:LDAP 目錄服務支持。
  • --with-curl:cURL 庫支持(現代 PHP 必備)。

現代 PHP (8.x) 常用編譯參數對比

./configure \
--prefix=/usr/local/php8 \
--with-config-file-path=/usr/local/php8/etc \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--enable-mbstring \
--enable-xml \
--enable-bcmath \
--enable-sockets \
--enable-zip \
--enable-soap \
--enable-pcntl \
--enable-opcache \
--with-curl \
--with-zlib \
--with-openssl \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-gd \
--with-freetype \
--with-jpeg \
--with-webp \
--with-zip \
--with-sodium \
--with-pear

主要變化:

  • 內建 mysqlnd 驅動,無需外部 MySQL 客戶端庫。
  • 移除 --with-apxs,主流採用 PHP-FPM + Nginx 架構。
  • 新增 --enable-opcache、--with-sodium (現代加密)、--with-webp 等。
  • GD 參數簡化:--with-freetype --with-jpeg --with-webp。

編譯安裝通用流程

  1. ./configure [參數...]
  2. make (可加 -j$(nproc) 並行編譯)
  3. make test (可選,運行測試套件)
  4. make install
  5. 配置 php.ini、php-fpm.conf、系統服務。

結語

PHP 4 系列已停止維護超 15 年,存在已知安全漏洞。所有新項目及存量項目均應計劃遷移至 PHP 8.x 長期支持版本。

copyright © 萬盛學電腦網 all rights reserved