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

更新Web服务器后Windows Server 2016下PHP CLI无法加载PG扩展求助

PHP CLI无法加载pdo_pgsql/pgsql扩展(仅Windows Server2016环境)

更新PHP+Apache的Web服务器后,仅Windows Server2016生产机的CMD环境下PHP CLI无法加载pdo_pgsql和pgsql扩展,Apache环境可正常加载并访问PGSQL表;Win10测试机(配置一致,仅Postgres版本不同)无此问题。


环境信息

  • 服务器差异:
    • Windows Server2016生产机:搭载Postgres 14,使用D:\WEB_Server\PostgreSQL\14\bin\libpq.dll
    • Win10测试机:搭载Postgres 15,使用对应版本libpq.dll
  • 通用运行版本:Apache/2.4.39 (Win64) OpenSSL/1.1.1c PHP/7.3.7RC3

配置文件

php.ini相关配置

...
;extension=bz2
;extension=curl
extension=fileinfo
extension=gd2
;extension=gettext
;extension=gmp
extension=intl
extension=imap
;extension=interbase
;extension=ldap
extension=mbstring
;extension=exif      ; Must be after mbstring as it depends on it
;extension=mysqli
;extension=oci8_12c  ; Use with Oracle Database 12c Instant Client
;extension=odbc
extension=openssl
;extension=pdo_firebird
;extension=pdo_mysql
;extension=pdo_oci
extension=pdo_odbc
extension=pdo_pgsql
;extension=pdo_sqlite
extension=pgsql
;extension=shmop
extension=php_pdo_sqlsrv_73_ts_x64
extension=php_sqlsrv_73_ts_x64
...

httpd.conf相关配置

...
LoadModule ssl_module modules/mod_ssl.so
LoadModule status_module modules/mod_status.so
#LoadModule substitute_module modules/mod_substitute.so
#LoadModule unique_id_module modules/mod_unique_id.so
#LoadModule userdir_module modules/mod_userdir.so
#LoadModule usertrack_module modules/mod_usertrack.so
#LoadModule version_module modules/mod_version.so
#LoadModule vhost_alias_module modules/mod_vhost_alias.so
#LoadModule watchdog_module modules/mod_watchdog.so
#LoadModule xml2enc_module modules/mod_xml2enc.so
LoadFile "D:/WEB_Server/PostgreSQL/14/bin/libpq.dll"
LoadModule php7_module "D:/WEB_Server/PHP/php7apache2_4.dll"
... 
PHPIniDir "D:\WEB_Server\PHP"

报错信息

CMD执行PHP命令时的警告:

PHP Warning:  PHP Startup: Unable to load dynamic library 'pdo_pgsql' (tried: 
D:\WEB_Server\PHP\ext\pdo_pgsql (The specified module could not be found.),
D:\WEB_Server\PHP\ext\php_pdo_pgsql.dll (The specified module could not be found.)) in Unknown on line 0
    
PHP Warning:  PHP Startup: Unable to load dynamic library 'pgsql' (tried:
D:\WEB_Server\PHP\ext\pgsql (The specified module could not be found.),
D:\WEB_Server\PHP\ext\php_pgsql.dll (The specified module could not be found.)) in Unknown on line 0

php -m输出:

D:\WEB_Server\PHP>php -m
PHP Warning:  PHP Startup: Unable to load dynamic library 'pdo_pgsql' (tried: D:\WEB_Server\PHP\ext\pdo_pgsql (The specified module could not be found.), D:\WEB_Server\PHP\ext\php_pdo_pgsql.dll (The specified module could not be found.)) in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'pgsql' (tried: D:\WEB_Server\PHP\ext\pgsql (The specified module could not be found.), D:\WEB_Server\PHP\ext\php_pgsql.dll (The specified module could not be found.)) in Unknown on line 0
[PHP Modules]
bcmath
calendar
Core
ctype
date
dom
fileinfo
filter
gd
hash
iconv
imap
intl
json
libxml
mbstring
mysqlnd
openssl
pcre
PDO
PDO_ODBC
pdo_sqlsrv
Phar
readline
Reflection
session
SimpleXML
SPL
sqlsrv
standard
tokenizer
wddx
xml
xmlreader
xmlwriter
zip
zlib

[Zend Modules]

php -v输出:

D:\WEB_Server\PHP>php -v
PHP Warning:  PHP Startup: Unable to load dynamic library 'pdo_pgsql' (tried: D:\WEB_Server\PHP\ext\pdo_pgsql (The specified module could not be found.), D:\WEB_Server\PHP\ext\php_pdo_pgsql.dll (The specified module could not be found.)) in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'pgsql' (tried: D:\WEB_Server\PHP\ext\pgsql (The specified module could not be found.), D:\WEB_Server\PHP\ext\php_pgsql.dll (The specified module could not be found.)) in Unknown on line 0
PHP 7.3.7RC3 (cli) (built: Jun 20 2019 16:57:39) ( ZTS MSVC15 (Visual C++ 2017) x64 )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.7RC3, Copyright (c) 1998-2018 Zend Technologies

已完成的测试

  • 注释php.ini中的pdo_pgsql和pgsql扩展后,Apache会停止加载这些模块,证明配置生效
  • 服务器上无其他php.ini文件
  • 两台机器的phpinfo显示PostgreSQL(libpq)版本为PostgreSQL 9.6.12 (win32),但实际使用的libpq.dll版本分别为15.1(测试机)和14.3(生产机)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.17 19:53:16