Install PostgreSQL in XAMPP on Windows and integrate phpPgAdmin tool

Sep 16 2016

Install PostgreSQL in XAMPP on Windows and integrate phpPgAdmin tool

I just installed PostgreSQL in my local machine, since I am using XAMP. It is easy to integrate into XAMPP. This article helps you to install and integrate PostgreSQL in XAMPP.

Installing postgreSQL

  1. Download the postgreSQL installer from EnterpriseDB.
  2. Run the installer and follow the instructions.
  3. Assuming XAMPP is located in C:\xampp; using the pgSQL installer, install postgreSQL, choose C:\xampp\pgsql\9.5 folder.
  4. It will ask you to set a password for postgres root user.
  5. Done, pgSQL has been installed.

Configure postgreSQL with PHP

  1. Open php.ini file located in C:\xampp\php.
  2. Uncomment the following lines in php.ini



  1. Add the below code snippet to httpd.conf file located on C:\xampp\apache.

LoadFile “C:\xampp\php\libpq.dll”

  1. Restart Apache.

Now we need to install web based management tool for postgreSQL.  There is phppgAdmin for postgreSQL like phpmyadmin for MYSQL.

Integrating phpPgAdmin to XAMPP – postgreSQL Database Administration tool

  1. phpPgAdmin is powered by team.
  2. To download phpPgAdmin go to the Github repository and clone the repository to C:\xampp\phppgadmin.

                Or download the repository as a Zip, and extract the content to C:\xampp\phppgadmin.

  1. Go to this folder location C:\xampp\phppgadmin\conf and rename the file to
  2. Now you need to edit the and replace all instances of the following with the values below.

$conf[‘servers’][0][‘host’] = ‘localhost’;


$conf[‘servers’][0][‘pg_dumpall_path’] = ‘C:\\xampp\\pgsql\\9.1\\pg_dumpall.exe’;

$conf[‘extra_login_security’] = false;

  1. Open XAMPP’s httpd-xampp.conf file located on C:\xampp\apache\conf\extra\ and add the below code.

Alias /phppgadmin “C:/xampp/phppgadmin/”

<directory “C:/xampp/phppgadmin”>

AllowOverride AuthConfig

Require all granted


  1. Restart Apache.
  2. You should now be able to use phpPgAdmin when you visit http://localhost/phppgadmin.

Example with PHP

To check connection use bellow code and run it. It will return FALSE on failure.


// Connecting, selecting database

$dbc port=5432 dbname=postgres user=postgres password=mypassword")  or die('Could not connect: ' . pg_last_error());



An example with simple operations


// Connecting, selecting database

$dbc port=5432 dbname=postgres user=postgres password=mypassword ")   or die('Could not connect: ' . pg_last_error());


// Performing SQL query

$query = 'SELECT * FROM authors';

$result = pg_query($query) or die('Query failed: ' . pg_last_error());


// Printing results in HTML

echo "<table>\n";

while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {

    echo "\t<tr>\n";

    foreach ($line as $col_value) {

        echo "\t\t<td>$col_value</td>\n";


    echo "\t</tr>\n";


echo "</table>\n";


// Free resultset



// Closing connection



I hope this article was useful to you.

Leave a Reply