How to add Postgres support to PHP installed by Homebrew?

I have already installed and configured new version of PHP with Homebrew, including MySQL support and XDebug. That works fine. However, I need to install the support for PostgreSQL as well. How can I do it?

I have figured out it is easy when installing PHP for the first time, just by adding the option:

homebrew install php53 --with-pgsql

How can I achieve something similar when my PHP is already installed, without reinstalling it completely? Or, if I reinstall, are all configs and additional settings, such as XDebug, kept?


Solution 1:

brew help does not show every option available. To get more details about all of the available commands, see man brew. In your case, you can run the reinstall command:

brew reinstall php53 --with-postgresql

According to the brew man page, this is synonymous with running uninstall and then install. It does appear that brew will back up known configuration files first.

If brew complains about not being able to find pg_config, then that means you need to install postgresql first -- it has to be postgresql; otherwise it'll never find pg_config. I spent an inordinate amount of time trying to figure out why --with-pgsql wouldn't work when I had the postgresql92 formulae installed.

I can personally confirm that it will not remove any custom configuration files.

Solution 2:

When php is already installed, you can just run brew install php55-pdo-pgsql

Solution 3:

If you use Homebrew:

ls /usr/local/Cellar/|grep php
php54

As you can see my homebrew version is for PHP 5.4, so I search Homebrew with:

brew search php54

In the search results, I see php54-pdo-pgsql.

So, I install the driver with:

brew install php54-pdo-pgsql

Then restart PHP.

Solution 4:

Thy Following on Mac OS X if you already have php installed.

brew install homebrew/php/php55-pdo-pgsql