在編譯安裝 PHP 擴展(如 memcache)時執行 phpize 報錯:
Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20060613
Zend Extension Api No: 220060519
Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable is set correctly and then rerun this script.
phpize 依賴 autoconf 生成 configure 腳本,而 autoconf 又依賴 m4 宏處理器。系統缺少這兩個工具導致構建流程中斷。
# 1. 安裝 m4
wget https://ftp.gnu.org/gnu/m4/m4-1.4.18.tar.gz # 建議用較新版本
tar -zxvf m4-1.4.18.tar.gz
cd m4-1.4.18
./configure && make && make install
cd ..
# 2. 安裝 autoconf
wget https://ftp.gnu.org/gnu/autoconf/autoconf-2.71.tar.gz
tar -zxvf autoconf-2.71.tar.gz
cd autoconf-2.71
./configure && make && make install
cd ..
# 3. 驗證
autoconf --version # 應輸出版本號
phpize -v # 應正常顯示 PHP Api Version 等信息
| 系統 | 命令 |
|---|---|
| CentOS/RHEL 7/8 | yum install -y autoconf m4 |
| Debian/Ubuntu | apt-get update && apt-get install -y autoconf m4 |
| Alpine | apk add autoconf m4 |
| macOS (Homebrew) | brew install autoconf m4 |
安裝完成後,重新進入擴展源碼目錄執行:
cd /path/to/ext-name
phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
最後在 php.ini 添加 extension=ext_name.so 並重啟 PHP-FPM。
$PHP_AUTOCONF 環境變量若系統安裝了多版本 autoconf,或安裝在非標準路徑,可顯式指定:
export PHP_AUTOCONF=/usr/local/bin/autoconf
export PHP_AUTOHEADER=/usr/local/bin/autoheader
加入 ~/.bashrc 或構建腳本中永久生效。