Installing and setup Apache, PHP and PostgreSQL are simple and straight forward. However, the PostgreSQL library (libpg) or pgsql may not enabled or loaded even all Apache, PHP and PostgrSQL are properly installed. There are a lot of information online, yet just doesn’t solve the problem that PostgreSQL libpg or pgsql is not loaded. Some information online recommends some installation or setup packages for ALL in ONE that will install and setup Apache, PHP and PostgreSQL properly. However, some (… like me) might dislike to use these installation packages that will also install some other files as well. We will share on how to make all these three items; Apache, PHP and PostgreSQL to be setup and configured properly.
Install Apache, PHP and PostgreSQL
We can download Apache, PHP and PostgreSQL installer from their official websites. Download installers and run them accordingly.
Once these components are properly installed, we can then view the PHP info by creating a php page.
<html> <body> <?php phpinfo(); ?> </body> </html>
Save this php page as phpinfo.php inside Apache htdocs folder; and view the result of this page by navigating to http://localhost/phpinfo.php on your web browser. If the phpinfo.php doesn’t show as below, then you may need to configure your php; move to next chapter for the detail of how to configure php.

If the pgsql is being loaded properly, then it should appear on the phpinfo.php page as below. If the pgsql info is not shown, then move to next chapter for configuring it.

Configuring PHP & PostgreSQL
In this chapter, we will discuss on how to configure your Apache and PHP to enable either PHP engine as well as PostgreSQL. First, we will enable PHP engine so that your Apache server is able to process PHP pages. Open the httpd.conf for edit. The httpd.conf is located at {apache_install_path}\conf\. Add the following lines into httpd.conf and save the file.
LoadFile "{replace with postgreSQL installation path}/bin/libpq.dll"
LoadModule php5_module "{replace with php installation path}/php5apache2_2.dll"
AddType application/x-httpd-php .php
PHPIniDir "{replace with php installation path}"
Here is an example of how a real httpd.conf looks like:
LoadFile "C:/My Program Files/PostgreSQL/8.3/bin/libpq.dll" LoadModule php5_module "C:/My Program Files/php/php5apache2_2.dll" AddType application/x-httpd-php .php PHPIniDir "C:/My Program Files/php"
Next, we need to configure PHP config file. Open and edit the php.ini file. The php.ini file is located at {php_installation_path}\. Search the following extensions and enable them. To enable them, we just need to remove “;” mark in front of them.
extension=php_pgsql.dll
Finally, you just need to restart Apache service to let these new configuration takes effect.

