You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在RHEL8.7编译PHP8.2.2时无法构建PostgreSQL扩展求助

编译PHP 8.2.2时PostgreSQL扩展报错的解决方法

问题描述

在RHEL8.7系统编译PHP-8.2.2,使用的configure命令:

./configure --prefix=/usr/www/php-8.2.2 --with-apxs2=/usr/www/httpd/bin/apxs --with-expat --with-openssl=/usr/www/openssl --with-zlib-dir=/usr/www/zlib --with-curl=/usr/www/curl --enable-soap --enable-sockets --with-pgsql=/usr/postgres --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-mbstring --without-pear --with-external-pcre

编译时触发错误:

checking whether to enable pcntl support... no
checking whether to enable PDO support... yes
checking for PDO_DBLIB support via FreeTDS... no
checking for Firebird support for PDO... no
checking for MySQL support for PDO... no
checking for the location of libz... /usr/www/zlib
checking Oracle OCI support for PDO... no
checking for ODBC v3 support for PDO... no
checking for PostgreSQL support for PDO... no
checking for sqlite 3 support for PDO... yes
checking for PDO includes... /home/lmwusr/terna/php-8.1.15/ext
checking for sqlite3 >= 3.7.7... yes
checking for sqlite3_close_v2 in -lsqlite3... yes
checking for sqlite3_column_table_name in -lsqlite3... yes
checking for PostgreSQL support... yes
checking for pg_config... /usr/postgres/bin/pg_config
checking for PQlibVersion in -lpq... no
configure: error: Unable to build the PostgreSQL extension: at least libpq 9.1 is required

已安装PostgreSQL 13且运行正常,相同配置编译PHP7.2无问题,但PHP-8.1.15、PHP-8.0.0均出现相同错误。当前环境变量:

export PKG_CONFIG_PATH=/usr/www/libxml2/lib/pkgconfig:/usr/www/openssl/lib/pkgconfig:/usr/www/curl/lib/pkgconfig::/usr/www/onig/lib/pkgconfig:/usr/postgres/lib/pkgconfig:/usr/www/pcre2/lib/pkgconfig
export LD_LIBRARY_PATH=/usr/postgres/lib

解决步骤

1. 验证pg_config输出准确性

执行/usr/postgres/bin/pg_config,确认输出的LIBS字段包含-lpq,INCLUDEDIR指向/usr/postgres/include。如果路径异常,说明PostgreSQL安装路径存在问题,需修正后再编译。

2. 显式指定PostgreSQL头文件与库路径

PHP 8.x对依赖检测逻辑更严格,在configure命令中添加头文件和库路径参数,替代单一的--with-pgsql:

./configure --prefix=/usr/www/php-8.2.2 --with-apxs2=/usr/www/httpd/bin/apxs --with-expat --with-openssl=/usr/www/openssl --with-zlib-dir=/usr/www/zlib --with-curl=/usr/www/curl --enable-soap --enable-sockets --with-pgsql=/usr/postgres --with-pgsql-include=/usr/postgres/include --with-pgsql-lib=/usr/postgres/lib --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-mbstring --without-pear --with-external-pcre

通过--with-pgsql-include和--with-pgsql-lib强制PHP使用指定的PostgreSQL开发文件。

3. 确保环境变量提前生效

执行以下命令验证环境变量是否正确加载:

echo $LD_LIBRARY_PATH
echo $PKG_CONFIG_PATH

如果输出不包含PostgreSQL路径,重新执行export命令,或把环境变量写入~/.bashrc//etc/profile后重新登录,确保全局生效。

4. 检查PostgreSQL开发包完整性

如果是RPM安装的PostgreSQL,需安装对应版本的开发包:

dnf install postgresql13-devel

如果是源码编译的PostgreSQL,重新执行make install,确保头文件和静态库被正确安装到/usr/postgres/include和/usr/postgres/lib目录。

5. 清理编译缓存

执行以下命令清除旧配置缓存,避免残留影响:

make clean
rm -rf config.cache

之后重新执行configure命令尝试编译。


内容的提问来源于stack exchange,提问作者Giulio

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 08:35:40