Enabling Postgresql Support in PHP on MAC Os X

Enabling PostgreSQL support in PHP on Mac OS X

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:

  1. Find your version of PHP: php -v.
  2. Download the version of PHP that matches yours: 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)
  3. Extract the archive you downloaded: tar -xzvf php-5.3.3.tar.gz
  4. Change to the PostgreSQL's extension directory: cd php-5.3.3/ext/pgsql/
  5. Type phpize.
  6. Type ./configure.
  7. Type make.
  8. Type sudo make install.
  9. Add the extension to you php.ini file by adding extension=pgsql.so. (You may already have done this)
  10. Restart Apache.

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:

  1. Type /usr/bin/ruby -e "$(/usr/bin/curl -fksSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)".
  2. Type sudo chown -R $USER /usr/local/Cellar.
  3. Type brew update.
  4. Type brew install autoconf.

That should install autoconf and allow you to install the module using the instructions above.

Install PHP with Postgresql on MAC using homebrew

I found a way to fix the problem. I installed postgresql with homebrew (even if it was already installed on my computer), then installed php5.6 with the following command line :

brew install php56 --without-mysql --without-apache --with-postgresql

Then I uninstall postgresql with homebrew

brew uninstall postgresql

And finally I installed php5.6 pdo-pgsql

brew install php56-pdo-pgsql

Hope it will help !

PHP not loading postgresql extensions ( mac os x)

Solution

The version i had wasn´t built with the --with-postgresql option in brew so i uninstalled the php56 and then reinstalled it with the option mentioned before following all the instructions

https://github.com/Homebrew/homebrew-php

You can get the post installation insctructions with brew info php56 in my case.

With the php built with postgresql you don´t need to add the pgsql.so and pdo_pgsql.so extensions in the php.ini file.



Related Topics



Leave a reply



Submit