在 Linux 環境下從源碼編譯 PHP 5.2.0 時,常會遇到缺少依賴庫或路徑配置錯誤。本文整理兩個典型錯誤及其解決方法,幫助你順利完成安裝。
checking for mysql_close in -lmysqlclient... no
checking for mysql_error in -lmysqlclient... no
configure: error: mysql configure failed. Please check config.log for more information.
PHP 編譯時找不到 MySQL 客戶端庫(libmysqlclient),通常是因為 MySQL 安裝路徑非標準位置,或未正確指定 --with-mysql 參數。
若 MySQL 是自行編譯安裝(如安裝在 /usr/local/mysql),需指定 目錄路徑 而非執行檔路徑:
./configure --with-mysql-dir=/usr/local/mysql ...
注意: 參數是 --with-mysql-dir,不是 --with-mysql。後者會嘗試尋找 mysql_config 腳本,若路徑不正確會失敗。
checking lex output file root... ./configure: line 2425: lex: command not found
configure: error: cannot find output from lex; giving up
系統缺少 flex 套件(lex 的 GNU 實作),PHP 編譯過程需要它來生成詞法分析器。
在 Red Hat/CentOS/Fedora 系列:
yum install flex
在 Debian/Ubuntu 系列:
apt-get install flex
或從安裝光碟掛載安裝 flex-2.5.4a-29.i386.rpm。安裝完成後重新執行 ./configure 即可。
| 錯誤提示 | 缺少套件 | 安裝指令 |
|---|---|---|
| mcrypt support | libmcrypt-devel | yum install libmcrypt-devel |
| mhash support | mhash-devel | yum install mhash-devel |
| libxml2 | libxml2-devel | yum install libxml2-devel |
| openssl | openssl-devel | yum install openssl-devel |
| curl | libcurl-devel | yum install libcurl-devel |
| gd (jpeg/png/freetype) | libjpeg-devel libpng-devel freetype-devel | yum install libjpeg-devel libpng-devel freetype-devel |
yum groupinstall "Development Tools"./configure --help 查看所有支援的選項,按需啟用擴展。yum install php 避免編譯麻煩。make test 驗證核心功能。掌握這些常見錯誤的排查思路,能大幅減少 PHP 源碼編譯的挫折感。