Search code examples
phpwindowsapache

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


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.


Solution

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