Apache PHP How To Enable PostgreSQL on Mac OS

Do you like this?

This article shows you how to enable PostgreSQL for PHP and Apache on Mac OS.


On Mac OS, Apache is pre-installed under /etc/apache2 and PHP script can be found at /usr/bin/php. When you want to enable PostgreSQL for PHP, you need to recompile PHP using the --with-pgsql configure option. For that, you have two options: either you download php source, configure with the --with-pgsql option and manually install it or you can install it with Homebrew. This article is not about installing Homebrew and many articles have already been written on how to set up Homebrew. Hence, I will skip this and go straight to the steps.

1) Add extra repositories:

brew tap josegonzalez/php
brew tap homebrew/dupes

After this, you can run brew search php and brew options php54 to see what's available.

2) Install PHP 5.4 with PostgreSQL option
brew install php54 --with-pgsql  --with-apache

3) Adding PHP script provided by Brew in PATH variable and before the default /usr/bin/php:
vim ~/.bashrc 
#add this line at the end: export PATH="$(brew --prefix josegonzalez/php/php54)/bin:$PATH"

4) Configuring Apache to use the PHP script provided by Brew
vim /etc/apache2/httpd.conf
#change the existing php5_module to LoadModule php5_module /usr/local/Cellar/php54/5.4.8/libexec/apache2/libphp5.so

5) Restart Apache
sudo apachectl restart

comments powered by Disqus