PHP警告:PHP启动:无法加载动态库’pdo_pgsql’和’pgsql’。

huangapple go评论88阅读模式
英文:

PHP Warning: PHP Startup: Unable to load dynamic library 'pdo_pgsql' and 'pgsql'

问题

经过数小时的搜索,我来到这里寻求帮助。
我在更新我的Web服务器(php和apache)后遇到了问题。我有一台测试机器(Win10)和一台生产机器(Server 2016)。两者的WEB配置相同,除了WINSRV2016安装了Postgres 14,而win10安装了Postgres 15。我使用基于Postgres安装的bin文件夹的不同版本的libpq.dll。

问题在于在WINSRV2016中(仅在CMD中),动态库未加载:

PHP Warning: PHP Startup: 无法加载动态库 'pdo_pgsql' (尝试:
D:\WEB_Server\PHP\ext\pdo_pgsql (找不到指定的模块。),
D:\WEB_Server\PHP\ext\php_pdo_pgsql.dll (找不到指定的模块。)) 位于未知位置的第 0 行

PHP Warning: PHP Startup: 无法加载动态库 'pgsql' (尝试:
D:\WEB_Server\PHP\ext\pgsql (找不到指定的模块。),
D:\WEB_Server\PHP\ext\php_pgsql.dll (找不到指定的模块。)) 位于未知位置的第 0 行

所以在使用CMD启动php时会出现错误,在apache日志中没有错误。Web服务器可以正常加载pgsql表,只有在WINSRV2016上才会出现这个问题。在WIN10上,在CMD中没有错误。

两台计算机上运行的版本是:

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      ; 必须在mbstring之后,因为它依赖于它
;extension=mysqli
;extension=oci8_12c  ; 与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"

我已经测试过:

  • 如果我在php.ini中注释掉两个pg扩展,apache就会停止使用这些模块。
  • 在该服务器上我没有任何其他php.ini。
  • 奇怪的是,在两台机器上,phpinfo显示PostgreSQL(libpq)使用的是PostgreSQL 9.6.12(win32),但分别指向版本为15.1和14.3的文件。

php -m的输出:

D:\WEB_Server\PHP>php -m
PHP Warning: PHP Startup: 无法加载动态库 'pdo_pgsql' (尝试:
D:\WEB_Server\PHP\ext\pdo_pgsql (找不到指定的模块。),
D:\WEB_Server\PHP\ext\php_pdo_pgsql.dll (找不到指定的模块。)) 位于未知位置的第 0 行
PHP Warning: PHP Startup: 无法加载动态库 'pgsql' (尝试:
D:\WEB_Server\PHP\ext\pgsql (找不到指定的模块。),
D:\WEB_Server\PHP\ext\php_pgsql.dll (找不到指定的模块。)) 位于未知位置的第 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: 无法加载动态库 'pdo_pgsql' (尝试:
D:\WEB_Server\PHP\ext\pdo_pgsql (找不到指定的模块。),
D:\WEB_Server\PHP\ext\php_pdo_pgsql.dll (找不到指定的模块。)) 位于未知位置的第 0 行
PHP Warning: PHP Startup: 无法加载动态库 'pgsql' (尝试:
D:\WEB_Server\PHP\ext\pgsql (找不到指定的模块。),
D:\WEB_Server\PHP\ext\php_pgsql.dll (找不到指定的模块。)) 位于未知位置的第 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

请告诉我如果你需要更多信息。我会编辑问题。谢谢。

英文:

After hours of searching I'm here, seeking help.
I have trouble after updating my web server: php and apache. I have one test machine(Win10) and production(Server 2016). Both have the same WEB configuration except WINSRV2016 have Postgres 14 and win10 have Postgres 15. I'm using different versions of libpq.dll, based on the postgres installation bin folder.

The problem is that on WINSRV2016(only in CMD), dynamic libraries are not loaded:

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

So when use CMD to start php have errors, there are no errors in apache logs. The web server load pgsql tables with no problems. This is happens only on WINSRV2016. On WIN10 there is no errors in CMD.

Versions running on both computers are:

Apache/2.4.39 (Win64) OpenSSL/1.1.1c PHP/7.3.7RC3

php.ini on both computers:

...
;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 on both pcs:

...
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"

I have tested:

  • If I comment the two pg extensions in php.ini, apache stops using this modules.
  • I don't have any other php.ini on that server.
  • Strange thing is that on both machines phpinfo says PostgreSQL(libpq) is using PostgreSQL 9.6.12 (win32) but it points to file with version 15.1 and 14.3 respectively.

output of 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

Please tell me if you need more info. I will edit the question. Thanks.

答案1

得分: 0

已解决问题。

  1. 因此,CLI使用位于PHP文件夹根目录中的libpq.dll,并与pgSQL服务器存在版本冲突。我已将PostgreSQL 14中的libpq复制到PHP文件夹中,并替换了WINSRV2016上的旧版本。那起作用了!
    在此之后,我尝试替换在工作服务器Win10上的文件,看看是否能正常工作。但它出现错误,我撤销了更改。

  2. 对于phpinfo中的旧版本libpq(9.6),我将PHP更新到7.4.8,该版本带有libpq 11.4。现在phpinfo使用的是11.4。
    奇怪的是,如果我将其替换为任何其他更新版本,它不会在CLI和Web中更新phpinfo()。

英文:

Just fixed the problem.

  1. So CLI is using the libpq.dll in the root of PHP folder, and has version conflict with pgSQL server. I have copied the libpq from PostgreSQL 14 in to PHP folder and replace the old version on WINSRV2016. That worked!
    After this I have tried to replace the file on the working server Win10 to see if will work. But it getting error and I revert the changes.

  2. For the old version of libpq(9.6) in phpinfo. I updated the php to 7.4.8 that is shipped with libpq 11.4. Now phpinfo is using 11.4.
    Strange if I replace it with any other newer version it doesn't update it in phpinfo() on CLI and Web.

huangapple
  • 本文由 发表于 2023年6月26日 20:46:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/76556828.html
  • apache
  • php
  • windows

如何在 :?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定