These instructions are for PostgreSQL 9.1 and higher, PostGIS 2.2 and higher that is compiled with raster support.Note: if you have postgis, without raster support, you can not use CREATE EXTENSION. Refer to PostGIS install.
After your PostgreSQL server is up and running, you’ll probably want to connect to it from your application. Here’s how to connect to PostgreSQL from popular programming languages and frameworks: PHP. To connect from PHP, make sure that it supports PostgreSQL. The version included with macOS doesn't support PostgreSQL. Bleeding Edge PostGIS extensions including with SFCGAL 3D support and PostGIS 2.4, and pgRouting 2.4 (built for PostgreSQL 9.3-9.6) - get from Winnie, the PostGIS windows build-bot. Winnie builds a fresh pot whenever any changes in PostGIS or pgRouting code base. How To Install Postgresql On Mac I started off programming Ruby on Rails applications on a Windows machine with an Ubuntu virtual machine running on top.
PostGIS is an optional extension that must be enabled in each database you want to use it in before you can use it. Installing the software is just the first step.DO NOT INSTALL it in the database called postgres
.
Connect to your database with psql
or PgAdmin. Run the following SQL.You need only install the features you want:
To upgrade PostGIS, you first have to install the latest binaries and then upgrade each database you have PostGIS installed in
For example connect to database you want to upgrade and if you just installed binaries for 2.1.3You can upgrade from 2.0 to 2.1, 2.2 et.c using this approach. To go from 1.* to 2.* you need to do a hard upgrade.Refer to PostGIS install for more extensive instructions.Note: that as of PostGIS 2.1.3 and PostGIS 2.0.6, you need to set environment variables to get full features.
or to a specific version
See the documentation for more guidance.
I’m having a terribly difficult time getting the command “pg_connect()” to work properly on my Mac. I’m currently writing a PHP script (to be executed from console) to read a PostgreSQL database and email a report.
I’ve gone into my php.ini
file and added
But, I’m met with the following error.
PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib/php/extensions/no-debug-non-zts-20090626/php_pgsql.so’ – dlopen(/usr/lib/php/extensions/no-debug-non-zts-20090626/php_pgsql.so, 9): image not found in Unknown on line 0
PHP Fatal error: Call to undefined function pg_connect() in… (blah file here)
When running phpinfo()
, I see nothing about PostgreSQL, so what is my issue here?
The PHP version that comes bundled with OS X doesn’t include PostgreSQL. You’ll have to compile the extension yourself. Here are some instructions:
php -v
.curl -O http://us.php.net/distributions/php-5.3.3.tar.gz
. (This example downloads PHP 5.3.3 but this must match your version)tar -xzvf php-5.3.3.tar.gz
cd php-5.3.3/ext/pgsql/
phpize
../configure
.make
.sudo make install
.php.ini
file by adding extension=pgsql.so
. (You may already have done this)Update for OS X Mountain Lion
Apple has removed autoconf
from the newer versions of XCode so the procedure above will fail at #5. To solve that problem:
/usr/bin/ruby -e '$(/usr/bin/curl -fksSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)'
.sudo chown -R $USER /usr/local/Cellar
.brew update
.brew install autoconf
.That should install autoconf
and allow you to install the module using the instructions above.
If you use home brew
, you can solve this with a command as simple as:
brew install php55-pdo-pgsql
for other php version, search with:
brew search pgsql
Install sources
Download the PHP source code. Unlike on Mountain Lion, you don’t get any headers preinstalled to link against so need to put it in /usr/include/php. Mavericks ships with PHP 5.4.17, but the latest 5.4.x source from php.net should do:
Configure PHP
Building a module
I needed the pdo_pgsql module – the same pattern should apply to just about any module assuming you have the necessary dependencies installed:
In my case I had the following error:
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script. ERROR:
`phpize’ failed
So I had to use this command:
Then:
After that I tried to do:
./configure
but I had the next problem:
checking for pg_config… not found configure: error: Cannot find
libpq-fe.h. Please specify correct PostgreSQL installation path
So the solution was to specify correct PostgreSQL installation path:
That copies pdo_pgsql.so to /usr/lib/php/extensions/no-debug-non-zts-20100525.
Then simply add
Run php -m
to confirm everything went to plan.
For those who installed php7/ngix/postgres with homebrew
You can install the PostgreSQL module with:
After that, you have to restart the php service:
I killed the whole day trying to make it work on El Capitan after I made an upgrade yesterday and it turned out that I forgot to modify httpd.conf
and change the path from the default php module (version 5.5.27) to the one I installed (version 5.6.14). This should be done in httpd.conf
by modifying your default LoadModule php5_module
path to LoadModule php5_module /usr/local/opt/php56/libexec/apache2/libphp5.so
.
Just decided to leave it here as the potential solution for those who upgrade their OS or just the PHP version and face the same problem.
OS X El Capitan users can simply upgrade their version of PHP 5.6. This is a one liner that will do that.
curl -s http://php-osx.liip.ch/install.sh | bash -s 5.6
PostgreSQL by default is installed in a unusual place on MAC OS X:
Given the location above you can type this:
For those of you having openssl error while make
here is the solution
OSX uses openssl 0.98 while installer is searching for 1.0.0
refer this link for instructions
I downloaded PostgreSQL for Mac, and used the stack builder after installation to standup the entire EnterpriseDB Apache/PHP stack end-to-end. I mention this as a possible time saving option, probably not ideal for all situations. Should work OK if the apache and postgres shipped with Mac OS X were never started.
To keep existing apache hosted applications (i.e. pre-PostgreSQL install legacy) stable, I would just install the newer EnterpriseDB apache on port 81 (stackbuilder will prompt for new port if legacy apache instance is already running). Then, use mod_proxy in httpd.conf for the apache running on port 80 to provide seamless user experience to applications hosted on PostgreSQL.
Tags: phpphp, post, postgresql, sql