本文記錄兩個歷史 PHP 版本的典型編譯配置參數,僅供遺留項目維護或版本演進研究參考。現代項目請使用 PHP 8.x 並參考官方文檔配置。
./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 支持 |
./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 必備)。./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 等。--with-freetype --with-jpeg --with-webp。./configure [參數...]make (可加 -j$(nproc) 並行編譯)make test (可選,運行測試套件)make installphp.ini、php-fpm.conf、系統服務。PHP 4 系列已停止維護超 15 年,存在已知安全漏洞。所有新項目及存量項目均應計劃遷移至 PHP 8.x 長期支持版本。