Home » Php » PHP not loading php_pgsql.dll on Windows

PHP not loading php_pgsql.dll on Windows

Posted by: admin April 23, 2020 Leave a comment


PHP 5.2.8 is refusing to load php_pgsql.dll, with the following error:

Warning: PHP Startup: Unable to load dynamic library ‘D:\PHP\ext\php_pgsql.dll’ – The specified module could not be found.

in Unknown on line 0

The .dll exists in PHP/ext/.

Has anyone else had this problem with PHP on Windows before?

How to&Answers:

Check out the info on the PHP PostgreSQL installation page: http://us.php.net/manual/en/pgsql.installation.php

On a Windows server, configured with Apache, adding the following line to httpd.conf to load libpq.dll can save you a lot of time :

LoadFile "C:/Program Files/PostgreSQL/8.4/bin/libpq.dll"

Note that you will have to change your folder accordingly to the installation path and version of PostgreSQL you have installed. Also note that having Apache and PostgreSQL on the same server for production environments is not recommended.

This fixed my setup instantly.


This happened to me also with PHP 5.4.1

Copying the offending DLL everywhere didn’t work, and I don’t have PostgreSQL installed in the server, but I also planned to use PHP against different Postgres versions, so the only solution I found that worked was to put in httpd.conf a line like this:

LoadFile "C:/Program Files/PostgreSQL/8.4/bin/libpq.dll"

And referring to the libpq.dll that comes bundled with PHP, like this:

LoadFile "C:/php/libpq.dll"

After that it worked fine to me.


For those willing to make their PHP install only capable to access PostGres servers, without actually installing PostGres, you need to:

  • enable php_pgsql.dll (and php_pdo_pgsql.dll, if using PDO) extension in PHP.INI,
  • make sure libpq.dll, libiconv-2.dll and libintl-8.dll are in the path. These are the php_pgsql.dll dependencies.

These 3 DLLs can be found in the PostGres install. I just copied them into apache\bin, that way I keep everything self contained. Doing that, apache can start the PHP engine just fine, with PostGres support.


The problem is with the related libraries used by php_pgsql.dll – like libpq.dll, the OpenSLL ones etc. You need to find them (from the zip distribution of Postgres, from an installed psqlODBC driver etc.) and put them in a folder which is in the PATH. As for the list of all DLLs – use MS Dependency Walker (depends.exe).

Another important bit – Apache (if you use Apache that is) has its own set of OpenSSL DLLs. Replace or just rename those so to not clash with those from the Postgres distribution.


You need to copy libpq.dll from wamp\bin\php\php5.3.5 to wamp\bin\apache\Apache2.2.17\bin. Again restart the Wamp Server. By now we are done with the php configuration. Next we will install phpPgAdmin and use it.


Just a thought — make sure that the Postgres binaries are in the SYSTEM path, not your user-specific path. As it happens, that was the problem on my machine. 🙂


Come to think of it, that explains why Dependency Walker would report all A-OK but the problem would still persist — you run DW under your own account, while Apache runs as SYSTEM, and hence won’t have your personal PATH settings available.


Just to share what worked for me, without dealing with libpq.dll. I uncommented both extension=php_pdo_pgsql.dll and extension=php_pgsql.dll in php.ini. At first, apache refused to start.

I then add "C:\Program Files (x86)\PostgreSQL\9.4\bin\" (depending on your installation) into windows environment PATH, started apache successfully and works.


Specifically for WAMP server setups here, you need to copy the libpg.dll file into “C:\wamp\bin\apache\Apache2.2.21\bin\”, or similar. Copying it to ..\php\ext\ and also adjusting the PATH env variable simply wasn’t enough (if effective at all).

Original answer sourced here: http://www.wampserver.com/phorum/read.php?2,40270,57932

Specifically for XAMPP setups, I found that I only needed to copy the libpg.dll file into ..\php\ext\ directory.


As Ondřej Bouda mentioned: Setting up Windows environment variables is enough. No copies of dlls, no entries to http-conf. Just add the php-directory (C:\xampp\php) to PATH. Don’t forget to restart XAMPP-Control-Panel if you use this, otherwise it won’t know the changes. (And restart Apache of cause.)

For instance, on XAMPP, it was sufficient to put the PHP directory
(i.e., C:\xampp\php) to the system PATH variable. – Ondřej Bouda


The only time I’ve seen this error (and the file name and ext path were definitely correct) was when I tried using an incorrect version of the DLL ie. I used one that was compiled against a different version of PHP to the one I was running.

Make sure your version is definitely the one compiled against PHP 5.2.8.

Edit: or, the permissions on the file were set incorrectly.


LIBPQ.DLL problem with php on Vista…

  • Check to make sure you actually have postgres installed. If you install php on windows with postgres API, without postgres being installed, you may get this warning. It’s too easy to just click everything on the Windows installer…

  • Comment out the relevant line in php.ini.


I got the solution:

1) If you want to load php_pdo_pgsql extension, please load php_pdo, too. (in php.ini)

2) php_pgsql.dll and php_pdo_pgsql.dll depend on libpq.dll and php5ts.dll. libpg.dll is the library from postgreSQL, but it has been bundled into PHP’s binary package.
When configuring PHP to work as a module with Apache, it can’t load the depending library correctly. And so you need to load it in Apache.

config in httpd.conf and the two lines should be before LoadModule php5_module

LoadFile “Full path to /php5gs.dll”
LoadFile “full path to libpg.dll”

Hope it be helpful.


You have to add the following lines to you httpd.conf file:

PHPIniDir "c:/PHP/"
Loadfile "C:\php\php5ts.dll"

Loadfile "C:\php\libpq.dll"

LoadModule php5_module "c:/PHP/php5apache2_2.dll"

Source: http://www.php.net/manual/en/pgsql.setup.php


This is an update to @Dayron Armas Peña ‘s answer. The php bundled pgsql ‘dll’ is found in the following location:

LoadFile "C:/wamp/bin/php/php5.4.12/libpq.dll"

Adding the above line to the httpd.conf file apart from uncommenting the required lines in the php.ini files has solved my problem.


I just did this and it worked just fine
in php folder inside php.ini I changed this line




the php_openssl.dll is inside ext folder which couldn’t be found.


Copy file libpq.dll from location /bin/php/ to
location /bin/apache//bin. Restart the wamp server.


I found this to work for me:

After installation of PostgreSQL, you need to copy libpq.dll from wamp\bin\php\phpX.X.X to wamp\bin\apache\Apache2.2*\bin. And restart the Wampserver.