Answer

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.

  • 84
Reply Report

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.

  • 46
Reply Report

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.

  • 6
Reply Report

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.

  • 4
Reply Report
      • 2
    • Sounds complex - but when I run a PHP -v from the command line it does throw an error saying libpq.dll couldn't be loaded. I may just move all my development to the ubuntu box tbh.
      • 1
    • For instance, on XAMPP, it was sufficient to put the PHP directory (i.e., C: mppphp) to the system PATH variable.

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.

  • 4
Reply Report

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. :-)

Edit:

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.

  • 2
Reply Report

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.

  • 2
Reply Report

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.

  • 1
Reply Report

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

  • 1
Reply Report

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.

  • 1
Reply Report

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.

  • 0
Reply Report
    • The permissions are fine and this is the dll I got with the PHP download so I assume it's compiled for the correct version. Any way I can check that?
      • 1
    • Hmmm, if it's the one that came with the download it should be fine. Sorry, out of ideas :-( .

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.

  • 0
Reply Report

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.

  • 0
Reply Report

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

extension=php_openssl.dll 

to

extension=C:\php\ext\php_openssl.dll 

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

  • 0
Reply Report

Warm tip !!!

This article is reproduced from Stack Exchange / Stack Overflow, please click

Trending Tags

Related Questions