Compiling and installing the
pdo_odbc PHP extension is not for the light of heart.
After a couple of hours and a lot of reading, I was able to get the
pdo_odbc extension working on my Mac.
I will try to document the entire process here including the installation of homebrew and the Xcode development tools, which are prerequisites to setting this up.
If you have already installed homebrew or the Xcode development tools, then you can skip the first two sections.
Install Homebrew and Xcode development tools
Install homebrew via: http://brew.sh/:
$ ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
Then, install Xcode development tools:
$ xcode-select --install
When prompted, click Install.
Next, install autoconf using the
brew install command:
$ brew install autoconf
Finally, create the necessary symlinks:
$ sudo ln -s /usr/local/Cellar/autoconf/2.69/bin/autoconf /usr/bin/autoconf
$ sudo ln -s /usr/local/Cellar/autoconf/2.69/bin/autoheader /usr/bin/autoheader
Build PHP from Source
Download PHP source code. The latest version at the time of this writing was 5.5: http://www.php.net/get/php-5.5.13.tar.gz/from/a/mirror
Next, open the Terminal application via: Application > Utilities > Terminal. Then browse to downloads folder and extract tarballs:
$ cd ~/Downloads
$ tar -xzvf php-5.5.13.tar.gz
Then, we need to PHPize the extension:
$ cd ~/Downloads/php-5.5.13/ext/pdo_odbc
configure the installation:
The last line of the output should indicate the configuration was setup correctly: config.status: creating config.h.
make to create the .so extension file
You should see a success massage indicating that the build was completed: Build complete.
Copy Extension module
Now that we have built our custom pdo_odbc binary we need to copy the pdo_odbc.so file to our PHP extensions directory:
$ sudo cp modules/`pdo_odbc`.so /usr/lib/php/extensions/
We’re almost there. Next, edit your php.ini file and add the extension:
$ sudo nano /etc/php.ini
Add the following line at the end:
Finally, restart Apache:
$ sudo apachectl restart