在 Linux 環境下從源碼編譯 PHP 時,configure 階段常因缺少依賴庫而報錯。本文彙總高頻錯誤及對應的 yum/apt 安裝命令,助你快速通過編譯配置。
| 錯誤信息 | 缺少套件 | CentOS/RHEL (yum) | Ubuntu/Debian (apt) |
|---|---|---|---|
| libevent >= 1.4.11 could not be found | libevent | yum -y install libevent libevent-devel | apt-get install libevent-dev |
| Please reinstall the mysql distribution | MySQL 開發包 | yum -y install mysql-devel | apt-get install libmysqlclient-dev |
| make: *** [sapi/fpm/php-fpm] error 1 | libiconv | make ZEND_EXTRA_LIBS='-liconv' | 同左 |
| XML configuration could not be found | libxml2 | yum -y install libxml2 libxml2-devel | apt-get install libxml2-dev |
| No curses/termcap library found | ncurses | yum -y install ncurses ncurses-devel | apt-get install libncurses5-dev |
| xml2-config not found | libxml2 | yum -y install libxml2 libxml2-devel | apt-get install libxml2-dev |
| Cannot find OpenSSL's <evp.h> | OpenSSL | yum install openssl openssl-devel | apt-get install libssl-dev |
| Please reinstall the libcurl distribution | libcurl | yum install curl curl-devel | apt-get install libcurl4-gnutls-dev |
| Cannot find ldap.h | OpenLDAP | yum install openldap openldap-devel | apt-get install libldap2-dev |
| libjpeg.(a|so) not found | libjpeg | yum install libjpeg libjpeg-devel | apt-get install libjpeg-dev |
| libpng.(a|so) not found | libpng | yum install libpng libpng-devel | apt-get install libpng-dev |
| freetype.h not found | freetype | yum install freetype-devel | apt-get install libfreetype6-dev |
| cannot find output from lex; giving up | flex | yum -y install flex | apt-get install flex |
| mod_deflate prerequisite failures | zlib, openssl | yum -y install zlib-devel openssl-devel | apt-get install zlib1g-dev libssl-dev |
| Unable to locate gmp.h | gmp | yum install gmp-devel | apt-get install libgmp-dev |
| Cannot find MySQL header files under /usr | MySQL 開發包 | yum install mysql-devel | apt-get install libmysqlclient-dev |
| Please reinstall the ncurses distribution | ncurses | yum install ncurses ncurses-devel | apt-get install libncurses5-dev |
| ODBC header file 'sqlext.h' not found | unixODBC | yum install unixODBC-devel | apt-get install unixodbc-dev |
| Cannot find pspell | aspell | yum install pspell-devel | apt-get install libaspell-dev |
| mcrypt.h not found | libmcrypt | yum install libmcrypt libmcrypt-devel | apt-get install libmcrypt-dev |
| snmp.h not found | net-snmp | yum install net-snmp net-snmp-devel | apt-get install libsnmp-dev |
| /usr/bin/ld: cannot find -lltdl | libtool | yum install libtool-ltdl-devel | apt-get install libltdl-dev |
# CentOS
yum install autoconf
# Ubuntu
apt-get install autoconf
需在擴展源碼目錄下執行 phpize,並確保目錄包含 config.m4。若為自建擴展,可用 ./ext_skel --extname=my_module 生成骨架,再編輯 config.m4 啟用 PHP_ARG_WITH 或 PHP_ARG_ENABLE。
yum groupinstall "Development Tools"(CentOS)或 apt-get install build-essential(Ubuntu)。./configure --help 查看所有可選參數,按需啟用擴展(如 --enable-fpm --with-mysqli --with-pdo-mysql)。make -j$(nproc) && make install。php.ini-production 到 /usr/local/php/lib/php.ini 並調整配置。大多數 configure 錯誤均因缺少 -devel/-dev 包導致。按表安裝對應依賴後重新執行 ./configure 即可解決。若遇到未列出的錯誤,請檢查 config.log 獲取詳細信息。