在編譯 PHP 時加入 --with-mysql 參數,configure 階段回報:
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.
config.log 進一步顯示:
/usr/bin/ld: skipping incompatible /usr/lib/mysql/libmysqlclient.so when searching for -lmysqlclient
/usr/bin/ld: skipping incompatible /usr/lib/mysql/libmysqlclient.a when searching for -lmysqlclient
/usr/bin/ld: cannot find -lmysqlclient
系統為 64 位元(x86_64),MySQL 開發函式庫安裝在 /usr/lib64/mysql/,但 PHP 編譯腳本預設搜尋 /usr/lib/mysql/,導致找不到相容的 libmysqlclient。
export LDFLAGS="-L/usr/lib64/mysql"
./configure --with-mysql --with-mysqli --with-pdo-mysql ...(其他參數)
若已執行 configure 產生 Makefile,可手動編輯:
# 將
-L/usr/lib/mysql
# 改為
-L/usr/lib64/mysql
修改後重新執行 make。
ln -s /usr/lib64/mysql/libmysqlclient.so /usr/lib/mysql/libmysqlclient.so
ln -s /usr/lib64/mysql/libmysqlclient.a /usr/lib/mysql/libmysqlclient.a
重新執行 configure 後,應看到:
checking for mysql_close in -lmysqlclient... yes
checking for mysql_error in -lmysqlclient... yes
接著 make && make install 即可完成安裝。
mysql_config --libs 查詢正確路徑。--with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd 使用原生驅動,避免外部函式庫相依問題。