萬盛學電腦網

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

PHP 動態編譯擴展報錯 "Cannot find autoconf" 解決方案

錯誤現場

在編譯安裝 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 宏處理器。系統缺少這兩個工具導致構建流程中斷。

解決步驟(源碼編譯安裝 m4 + autoconf)

# 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/8yum install -y autoconf m4
Debian/Ubuntuapt-get update && apt-get install -y autoconf m4
Alpineapk 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 或構建腳本中永久生效。

copyright © 萬盛學電腦網 all rights reserved