All the PHP developers out here, who use Windows is familiar with WAMP. I the WAMP stack we get a lot of packages like sqlbuddy and phpmyadmin. But a project came to me that uses PostgreSQL. So I had to install PostgreSQL in Wamp. Well it was a tricky job to do. At last I did it. So today in this topic I am going to share this with the developers who need to use PostgreSQL in Windows and Wamp.
In this article I am going to use,
- WampServer 2.1. Download it from Here.
- PostgreSQL 9.1. Download it from Here.
- phpPgAdmin 5.0.2. Download it from Here.
It is assumed that, you have installed the WampServer already. Now, let us proceed with the new Installations.
- First, install the PostgreSQL. It is a simple installation procedure. Just click Next Until, when you come to the screen where you give the installation directory. Make it to your suitable directory. I installed it in “C:wampappsPostgreSQL”. Then provide the Data path according to “C:wampappsPostgreSQL9.1data”.
- Then you will be presented a Password Screen where you can give the main login password. I have made it as “root“.
- Then in the next screen you will be prompted with the Port number. Make sure it does not conflict with the MySQL port 3306. So I used the default as 5432.
- Set the Locale as the Default Locale.
- Now click on Next and it will start the installation.
- Next click on Finish. And we are done with the installations.
- Check installation of PostgreSQL by clicking Start ->Programs ->PostgreSQL 9.1 ->PgAdmin III.
- Click on Server(1) and Right Click on PostgreSQL Database Server 9.1 (localhost:5432) and Select Connect to obtain a connection to server and give password. It will connect to Database server.
- Now it is time to bridge PHP to it. So Go on the task bar and Left Click on the Wamp Tray icon. Navigate to PHP > PHP extension. Then enable,
- php_pgsql
- php_pdo_pgsql extension.
- Restart the Wampserver. This time you will probably see some errors saying like,
- PHP Warning: PHP Startup: Unable to load dynamic library ‘C:wampbinphpphp5.3.5extphp_pdo_pgsql.dll’ – The specified module could not be found.
- PHP Warning: PHP Startup: Unable to load dynamic library ‘C:wampbinphpphp5.3.5extphp_pgsql.dll’ – The specified module could not be found.
- To eleminate them you need to copy libpq.dll from wampbinphpphp5.3.5 to wampbinapacheApache2.2.17bin. Again restart the Wamp Server. By now we are done with the php configuration. Next we will install phpPgAdmin and use it.
- So download phpPgAdmin and copy it in C:wampapps assuming, Wampserver is in C Drive. So the path will be, C:wampappsphpPgAdmin-5.0.2.
- To make a shortcut in Wamp Index page in the Your Aliases section create a file called, phppgadmin.conf in C:wampalias. And copy paste the following,
Alias /phppgadmin "C:/wamp/apps/phpPgAdmin-5.0.2/" <Directory "C:/wamp/apps/phpPgAdmin-5.0.2/"> Options Indexes FollowSymLinks MultiViews AllowOverride all Order Deny,Allow Allow from all </Directory>
- Restart the Wamp server and go to http://localhost/. You will see a link came under Your Aliases as phppgadmin. Click on that link and you will see the following screen.
- Then click on the PostgreSQL link on the left hand side. You will be prompted for the username and the password. By default postgrey creates an user called postgres. So give it in the username field and give the password same as you have entered in the time of the installation. For me it is root.
- Last we will see the following screen after successful login.
- Last is is time to test a simple database connection PHP script. So to do that, create a database called test and create a php page with the following code in it.
<?php $con="host=localhost port=5432 dbname=test user=postgres password=root"; $db=pg_connect($con) or die('connection failed'); echo 'Connected to: ', pg_dbname($db); ?>
If it does not show any error, then we are good to go. We can use PostgreSQL.
- If you face any problem then you can write to me. I will try to solve the problem.