Hendra Nicholas I am a software engineer, consultant and CEO at 41studio currently living in West Java, Indonesia. My interests range from programming to sport. I am also interested in entrepreneurship, technology, and design.

Enabling PostgreSQL support in PHP on Mac OS X

42 sec read

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 On Your Terminal by Type :

      $ 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 Your php File by Adding :

      extension=pgsql.so. (You may already have done this).

10. And 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 :

      $ /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.

Written by : Hendra Nicholas – Founder & CEO at 41studio

Hendra Nicholas I am a software engineer, consultant and CEO at 41studio currently living in West Java, Indonesia. My interests range from programming to sport. I am also interested in entrepreneurship, technology, and design.