PHP 源碼編譯時 ./configure 階段頻繁報缺少開發庫頭文件。本文匯總高頻錯誤與對應 yum install *-devel 解決命令,覆蓋 XML、圖像、數據庫、加密、郵件、LDAP、ODBC、SNMP、XSLT 等常見依賴,適合 CentOS/RHEL 系統快速排查。
| 錯誤信息關鍵字 | 缺失開發包 | 安裝命令 |
|---|---|---|
| xslt-config not found / libxslt | libxslt-devel | yum -y install libxslt-devel |
| net-snmp-config not found | net-snmp-devel | yum -y install net-snmp-devel |
| readline.h not found | readline-devel | yum -y install readline-devel |
| Cannot find pspell | aspell-devel | yum -y install aspell-devel |
| ODBC header sqlext.h not found | unixODBC-devel | yum -y install unixODBC-devel |
| ICU prefix / icu-config failed | libicu-devel | yum -y install libicu-devel |
| utf8_mime2text / U8T_CANONICAL | libc-client-devel | yum -y install libc-client-devel |
| freetype.h not found | freetype-devel | yum -y install freetype-devel |
| xpm.h not found | libXpm-devel | yum -y install libXpm-devel |
| png.h not found | libpng-devel | yum -y install libpng-devel |
| vpx_codec.h not found | libvpx-devel | yum -y install libvpx-devel |
| Cannot find enchant | enchant-devel | yum -y install enchant-devel |
| libcurl / easy.h not found | libcurl-devel | yum -y install libcurl-devel |
| mcrypt.h not found | libmcrypt-devel (需源碼編裝) | wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz && tar zxf ... && ./configure && make && make install |
| Cannot find imap | libc-client-devel + 軟鏈 | yum -y install libc-client-devel && ln -s /usr/lib64/libc-client.so /usr/lib/libc-client.so |
| Cannot find ldap.h / ldap libraries | openldap-devel | yum -y install openldap openldap-devel && cp -frp /usr/lib64/libldap* /usr/lib/ |
| libpq-fe.h not found | postgresql-devel | yum -y install postgresql-devel |
| sqlite3 not found | sqlite-devel | yum -y install sqlite-devel |
| BZip2 not found | bzip2-devel | yum -y install bzip2-devel |
| DBA header files not found | db4-devel | yum -y install db4-devel |
| jpeglib.h not found | libjpeg-devel | yum -y install libjpeg-devel |
| gmp.h not found | gmp-devel | yum -y install gmp-devel |
| xml2-config not found | libxml2-devel | yum -y install libxml2-devel |
| pcre.h not found | pcre-devel | yum -y install pcre-devel |
| MySQL header files not found | mysql-devel | yum -y install mysql-devel |
tail -50 config.log 定位具體缺失頭文件/庫路徑。find /usr -name "xxx.h" 確認文件是否存在但路徑不在默認搜尋目錄。./configure --with-xxx-dir=/custom/path 強制指定庫目錄。yum groupinstall "Development Tools" 確保 gcc、make、autoconf 等基礎工具齊全。yum install epel-release 獲取更多第三方庫包。./configure \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--enable-fpm \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-iconv-dir \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-mbstring \
--with-mcrypt \
--enable-ftp \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--with-gettext \
--enable-opcache \
--with-xsl \
--with-ldap \
--with-ldap-sasl
收藏此表,下次編譯 PHP 遇到 configure 報錯,一鍵 yum 解決,事半功倍。