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

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

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中),动态库未加载:

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

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

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

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

两台计算机上的php.ini:

  1. ...
  2. ;extension=bz2
  3. ;extension=curl
  4. extension=fileinfo
  5. extension=gd2
  6. ;extension=gettext
  7. ;extension=gmp
  8. extension=intl
  9. extension=imap
  10. ;extension=interbase
  11. ;extension=ldap
  12. extension=mbstring
  13. ;extension=exif ; 必须在mbstring之后,因为它依赖于它
  14. ;extension=mysqli
  15. ;extension=oci8_12c ; Oracle Database 12c Instant Client一起使用
  16. ;extension=odbc
  17. extension=openssl
  18. ;extension=pdo_firebird
  19. ;extension=pdo_mysql
  20. ;extension=pdo_oci
  21. extension=pdo_odbc
  22. extension=pdo_pgsql
  23. ;extension=pdo_sqlite
  24. extension=pgsql
  25. ;extension=shmop
  26. extension=php_pdo_sqlsrv_73_ts_x64
  27. extension=php_sqlsrv_73_ts_x64
  28. ...

两台计算机上的httpd.conf:

  1. ...
  2. LoadModule ssl_module modules/mod_ssl.so
  3. LoadModule status_module modules/mod_status.so
  4. #LoadModule substitute_module modules/mod_substitute.so
  5. #LoadModule unique_id_module modules/mod_unique_id.so
  6. #LoadModule userdir_module modules/mod_userdir.so
  7. #LoadModule usertrack_module modules/mod_usertrack.so
  8. #LoadModule version_module modules/mod_version.so
  9. #LoadModule vhost_alias_module modules/mod_vhost_alias.so
  10. #LoadModule watchdog_module modules/mod_watchdog.so
  11. #LoadModule xml2enc_module modules/mod_xml2enc.so
  12. LoadFile "D:/WEB_Server/PostgreSQL/14/bin/libpq.dll"
  13. LoadModule php7_module "D:/WEB_Server/PHP/php7apache2_4.dll"
  14. ...
  15. 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的输出:

  1. D:\WEB_Server\PHP>php -m
  2. PHP Warning: PHP Startup: 无法加载动态库 'pdo_pgsql' (尝试:
  3. D:\WEB_Server\PHP\ext\pdo_pgsql (找不到指定的模块。),
  4. D:\WEB_Server\PHP\ext\php_pdo_pgsql.dll (找不到指定的模块。)) 位于未知位置的第 0
  5. PHP Warning: PHP Startup: 无法加载动态库 'pgsql' (尝试:
  6. D:\WEB_Server\PHP\ext\pgsql (找不到指定的模块。),
  7. D:\WEB_Server\PHP\ext\php_pgsql.dll (找不到指定的模块。)) 位于未知位置的第 0
  8. [PHP Modules]
  9. bcmath
  10. calendar
  11. Core
  12. ctype
  13. date
  14. dom
  15. fileinfo
  16. filter
  17. gd
  18. hash
  19. iconv
  20. imap
  21. intl
  22. json
  23. libxml
  24. mbstring
  25. mysqlnd
  26. openssl
  27. pcre
  28. PDO
  29. PDO_ODBC
  30. pdo_sqlsrv
  31. Phar
  32. readline
  33. Reflection
  34. session
  35. SimpleXML
  36. SPL
  37. sqlsrv
  38. standard
  39. tokenizer
  40. wddx
  41. xml
  42. xmlreader
  43. xmlwriter
  44. zip
  45. zlib
  46. [Zend Modules]

php -v的输出:

  1. D:\WEB_Server\PHP>php -v
  2. PHP Warning: PHP Startup: 无法加载动态库 'pdo_pgsql' (尝试:
  3. D:\WEB_Server\PHP\ext\pdo_pgsql (找不到指定的模块。),
  4. D:\WEB_Server\PHP\ext\php_pdo_pgsql.dll (找不到指定的模块。)) 位于未知位置的第 0
  5. PHP Warning: PHP Startup: 无法加载动态库 'pgsql' (尝试:
  6. D:\WEB_Server\PHP\ext\pgsql (找不到指定的模块。),
  7. D:\WEB_Server\PHP\ext\php_pgsql.dll (找不到指定的模块。)) 位于未知位置的第 0
  8. PHP 7.3.7RC3 (cli) (built: Jun 20 2019 16:57:39) ( ZTS MSVC15 (Visual C++ 2017) x64 )
  9. Copyright (c) 1997-2018 The PHP Group
  10. 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:

  1. PHP Warning: PHP Startup: Unable to load dynamic library 'pdo_pgsql' (tried:
  2. D:\WEB_Server\PHP\ext\pdo_pgsql (The specified module could not be found.),
  3. D:\WEB_Server\PHP\ext\php_pdo_pgsql.dll (The specified module could not be found.)) in Unknown on line 0
  4. PHP Warning: PHP Startup: Unable to load dynamic library 'pgsql' (tried:
  5. D:\WEB_Server\PHP\ext\pgsql (The specified module could not be found.),
  6. 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:

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

php.ini on both computers:

  1. ...
  2. ;extension=bz2
  3. ;extension=curl
  4. extension=fileinfo
  5. extension=gd2
  6. ;extension=gettext
  7. ;extension=gmp
  8. extension=intl
  9. extension=imap
  10. ;extension=interbase
  11. ;extension=ldap
  12. extension=mbstring
  13. ;extension=exif ; Must be after mbstring as it depends on it
  14. ;extension=mysqli
  15. ;extension=oci8_12c ; Use with Oracle Database 12c Instant Client
  16. ;extension=odbc
  17. extension=openssl
  18. ;extension=pdo_firebird
  19. ;extension=pdo_mysql
  20. ;extension=pdo_oci
  21. extension=pdo_odbc
  22. extension=pdo_pgsql
  23. ;extension=pdo_sqlite
  24. extension=pgsql
  25. ;extension=shmop
  26. extension=php_pdo_sqlsrv_73_ts_x64
  27. extension=php_sqlsrv_73_ts_x64
  28. ...

httpd.conf on both pcs:

  1. ...
  2. LoadModule ssl_module modules/mod_ssl.so
  3. LoadModule status_module modules/mod_status.so
  4. #LoadModule substitute_module modules/mod_substitute.so
  5. #LoadModule unique_id_module modules/mod_unique_id.so
  6. #LoadModule userdir_module modules/mod_userdir.so
  7. #LoadModule usertrack_module modules/mod_usertrack.so
  8. #LoadModule version_module modules/mod_version.so
  9. #LoadModule vhost_alias_module modules/mod_vhost_alias.so
  10. #LoadModule watchdog_module modules/mod_watchdog.so
  11. #LoadModule xml2enc_module modules/mod_xml2enc.so
  12. LoadFile "D:/WEB_Server/PostgreSQL/14/bin/libpq.dll"
  13. LoadModule php7_module "D:/WEB_Server/PHP/php7apache2_4.dll"
  14. ...
  15. 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:

  1. D:\WEB_Server\PHP>php -m
  2. 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
  3. 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
  4. [PHP Modules]
  5. bcmath
  6. calendar
  7. Core
  8. ctype
  9. date
  10. dom
  11. fileinfo
  12. filter
  13. gd
  14. hash
  15. iconv
  16. imap
  17. intl
  18. json
  19. libxml
  20. mbstring
  21. mysqlnd
  22. openssl
  23. pcre
  24. PDO
  25. PDO_ODBC
  26. pdo_sqlsrv
  27. Phar
  28. readline
  29. Reflection
  30. session
  31. SimpleXML
  32. SPL
  33. sqlsrv
  34. standard
  35. tokenizer
  36. wddx
  37. xml
  38. xmlreader
  39. xmlwriter
  40. zip
  41. zlib
  42. [Zend Modules]

php -v:

  1. D:\WEB_Server\PHP>php -v
  2. 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
  3. 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
  4. PHP 7.3.7RC3 (cli) (built: Jun 20 2019 16:57:39) ( ZTS MSVC15 (Visual C++ 2017) x64 )
  5. Copyright (c) 1997-2018 The PHP Group
  6. 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
匿名

发表评论

匿名网友

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

确定