Aug 9, 2011

Recompile PHP with Postgres support in OSX



If you've switched over your local development to PostgreSQL on your mac, you may want to use a graphical interface to interact with your databases and tables. One solution out there is phpPgAdmin. Unfortunately if you try to load it up you'll probably get an error saying that postgres support isn't enabled. Instructions on Apple's site will tell you to recompile PHP with postgres support and unfortunately there's no real way to avoid that. Here, I'll step you through how to do it.


Step 1: Find, download, and extract your version of PHP

php -v

On my version of Snow Leopard it was PHP 5.3.4. To get it, visit the PHP site and download the corresponding version. Note that it may be in the archive section

curl -O http://museum.php.net/php5/php-5.3.4.tar.gz
tar -xzvf php-5.3.4.tar.gz

Step 2: Pre configuration
Change to the PostgreSQL's extension directory:
cd php-5.3.4/ext/pgsql/ 
phpize

Step 3: Configure
I'm using homebrew (you should be too) and installed postgres using these great instructions (also see the screencast)

Since homebrew puts postgres in a different directory, we'll need to specify it when we configure. As of August 8, the version of Postgres installed by homebrew is 9.0.4. Check your version before you blindly copy/paste my instructions.

./configure --with-pgsql=/usr/lo./configure --with-pgsql=/usr/local/Cellar/postgresql/9.0.4/bin
make
sudo make install

Step 4: Modify your php.ini file
You may not have a php.ini file so if you don't the first thing you'll want to do is create it

sudo cp /etc/php.ini.default /etc/php.ini

Next, add this line somewhere in your file

extension=pgsql.so

Step 5: Restart Apache
The easiest way to do this on MacOS X is to go to your System Preferences → Sharing settings and turning off and back on Web Sharing.

With that all done, visiting your local copy of phpPgAdmin should now work. One last tip, if you can't login because your postgres user doesn't have a password, you can modify your conf/config.inc.php file and change the conf['extra_login_security'] to false.

$conf['extra_login_security'] = false;


Update (Sept 08-2011): Two other tips. On lion, be sure that /usr/local/bin is ahead of /usr/bin in your $PATH. Run brew doctor to see if this applies to you:

brew doctor

Also, in your conf/config.inc.php make sure you set the host to localhost:

$conf['servers'][0]['host'] = 'localhost';

No comments:

Post a Comment