How Do You Integrate PHP with Postgresql?

Problem scenario
You want your PHP files (either a frontend web page or a purely backend script) to integrate with Postgres.  You want .php files to log into a Postgres database to run SQL commands.  How do you do this?

Install php5-pgsql or php7.0-pgsql.  It depends on your version of PHP.  Use this command to find out what version of PHP you have:  php --version

Install this module:  libapache2-mod-php.  As root or with a "sudo " in front of this command, run:
apt-get -y install libapache2-mod-php

To install the php pgsql package on Ubuntu, you should run a command like one of these as root:  
apt-get install php5-pgsql
apt-get install php7.0-pgsql

Leave a comment

Your email address will not be published. Required fields are marked *