Tuesday, March 29, 2011

Adding PHP module to default OS 10.6.1 PHP stack

The current system is Snow Leopard 10.6.1 and I want to add PostgreSQL support to the default PHP installation.  Snow Leopard comes with PHP 5.3.4 already installed in Apple's weird, distributed way.  However, the current distro for PHP is 5.3.6 at the time of this writing, so what to do?  I found the solution scattered across many different blogs, so I am synthesizing it here.  None of this was my own creation.

First, grab a copy of the source code that matches what is already installed.  Probably won't find it on PHP.net, so try this link: php-5.3.4

I created a /src directory to store source code in.  Copy the tar file into here or a similar directory and unpack it.

Change to that directory:


>cd /src/php-5.3.4

Set some environment variables before doing the configuration

>export MACOSX_DEPLOYMENT_TARGET=10.6.7
>export CFLAGS="-arch x86_64"
>export CXXFLAGS="-arch x86_64"
>export LDFLAGS="-arch x86_64"

Go to the pgsql source directory in php ext folder

>cd ext/pgsql

Compile the extension module

>phpize
>./configure
>make

The extension will be found here

>cd /src/php-5.3.4/ext/pgsql/.libs/
>ls
-rwxr-xr-x  1 Bali  admin   154K Mar 29 12:41 pgsql.so

Copy the extension to the extensions library and make sure it is executable

>sudo cp pgsql.so 
/usr/lib/php/extensions/no-debug-non-zts-20090626/
>cd  
/usr/lib/php/extensions/no-debug-non-zts-20090626/
>sudo chmod +x pgsql.so

Create a copy of the php.ini file if one does not already exist

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

Edit the php.ini file and add the following two lines:

extension_dir="/usr/lib/php/extensions/no-debug-non-zts-20090626/"
extension=pgsql.so

Save and then test that the extension is loaded properly by running the following at the command line:

>php -m

You should see a list of installed modules, including pgsql.  Then go back and restart Apache

>/usr/sbin/apachectl graceful

Run phpinfo to verify the module has been loaded.  You may have to scroll down to see it.

That is it.

No comments:

Post a Comment