Over the weekend, I decided to learn postgreSQL Database. For me to be able to achieve it, I need to as a matter of fact install and get it running on my local machine.
Since I’m using XAMPP already as my LAMP stack, it will be easier to just integrate postgreSQL into it rather than compiling it with PHP from scratch.
In this article, I will show us how I was able to install and integrate postgreSQL to XAMPP as well as pgAdmin and phpPgadmin in Windows.
The reason prefer using xampp?i think, because MySQL is more widely used with PHP.In addition, if the web want to be online on web hosting for example, that. XAMPP takes away the hassle of setting up Apache, MariaDB, PHP, Perl, PhpMyadmin, FTP and Tomcat. XAMPP is configured with all the features turned on and optimised for speed and performance. Perfect solution for setting up a web server. Great alternative to WAMP or LAMP. MariaDB works well as same as MySQL and respond to PHP's built-in MySQL function alike. XAMPP is again a 'Apachefriends' child, that most community hate MySQL's acquisition by the Oracle Inc. So this is obvious that it is ditched from XAMPP. Previous versions of XAMPP were included MySQL but not the latest. Stop any running instance of Apache and MySQL in the xampp control panel and rename the old xampp/mysql folder in the xampp directory to xampp/mariadb. Then create a new empty directory namely mysql and extract the content of the zip download in the first step inside the new folder.
- Download the postgreSQL installer from EnterpriseDB.
- Run the installer and follow the on-screen instruction.
Note: pgAdmin also get installed alongside.
- Assuming XAMPP is located in C:xampp; using the pgSQL installer, install postgreSQL in say C:xampppgsql9.1 folder.
- You will be prompted to set a password for postgres root user.
- By now, pgSQL has been installed.
Getting postgreSQL to talk with PHP
We need to perform the following rituals to get PHP talking / communicating with pgSQL.
- Open php.ini file located in C:xamppphp.
- Uncomment the following lines in php.iniextension=php_pdo_pgsql.dll
- Add the below code snippet to httpd.conf
postgreSQL Database Administration tool
When we were installing postgreSQL, pgAdmin – a graphical pgSQL database administration tool was installed alongside.
There is also phpPgAdmin (web base Postgres database management tool) which is to postgreSQL what phpMyAdmin is to MySQL / MariaDB.
If you are like me that is intimidated by the command line, you will find these tools useful.
To get started with pgAdmin in creating and managing postgres database; firstly create a server, connect to it and create the database for that project of yours.
Let’s start with creating the server.
- Click on File > Add Server…
- Fill the form as shown in the image below.
Take note: in the username and password field, insert postgres as the username and in the password field, the password you entered while installing postgreSQL.
You can now go ahead to create a Database.
To create the database, under the server we created, right-click on the Database menu and click the New Database… link.
Xampp With Mariadb 10.3
I will be integrating phpPgAdmin to XAMPP to just have a MySQL-like XAMPP experience.
- Head over to the Github repository and clone the repo to C:xamppphppgadmin.
Alternatively, download the repo. as a Zip, and extract the content to C:xamppphppgadmin.
- In C:xamppphppgadminconf, rename the config.inc.php-dist file to config.inc.php
- Edit the config.inc.php and replace all instances of the following with the values below.
- Edit XAMPP’s
httpd-xampp.confand add the below code.
- Restart Apache
- You should now be able to use phpPgAdmin when you visit http://localhost/phppgadmin.
Putting pgSQL and PHP to test
I will be creating a test that check a PHP connection to postgres using pg_connect().
If successful, PostgreSQL connection resource is returned or FALSE on failure.
Xampp Apache Mariadb
I hope you found this guide useful.