18

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?

1
  • The same applies for --with-mysql, I guess...
    – Pavel S.
    Aug 22, 2013 at 12:07

7 Answers 7

23

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.

2
  • 5
    --with-pgsql is deprecated. Use --with-postgresql
    – tinkerr
    Aug 26, 2015 at 0:14
  • This definitely worked for me! Oct 12, 2016 at 8:53
15

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

1
  • 2
    this is for the pdo driver only, not the pgsql extension Feb 16, 2015 at 19:53
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.

3

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

brew install homebrew/php/php55-pdo-pgsql
2
  • I don't see how that is substantially different from earlier answers.
    – kasperd
    Dec 14, 2016 at 22:25
  • Above commands didn't work for me this worked.
    – Mitul
    Dec 22, 2016 at 17:40
2

If you did install php with brew, you have to restart the php after you install any module:

brew services restart php70

after that you can use the new installed module.

1

I had a similar problem with PHP55 and solved it with uninstalling (brew uninstall php55) and reinstalling (brew install php55 --with-postgresql ).

0

Similar to above answers, though none of those worked quite well enough in my case, I used brew reinstall php70 --with-postgresql rather than un/install, which failed because of linked dependencies.

Follow that with brew services restart php70 as suggested above, and sudo apachectl restart for good measure.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .