PHP MSSQL & PDO_DBLIB (FreeTDS) support on Mac OSX 10.9 Mavericks

So since upgrading to Mavericks I have lost the ability to use PHP’s MSSQL and PDO_DBLIB database extensions. I had previously set this up on Lion/Mountain Lion.

You’ll need to download the latest Xcode from the Mac App Store and then run it and install the command line tools. This will allow you to build the packages below.

We’ll also need autoconf so download the latest source at autoconf-latest.tar.gz. At the time this article was published the latest release was v2.69.

Extract this and then using terminal navigate to the extracted source directory and run the below commands:

Now on to FreeTDS, this is the library that will connect to MSSQL. Visit this link to get the latest stable version of FreeTDS: freetds-stable.tgz.
At the time this article was published the latest stable release was v0.91.

Once it’s downloaded and extracted, again in terminal, navigate to the the extracted directory. Now enter the below commands to build and install the driver.

Hopefully that all went well and there were no errors.

Now its time to build the PHP MSSQL and PDO_DBLIB extensions. Use the link below to download the Mavericks PHP source from Apple and then extract the archive.
php-5.4.17.tar.bz2 from Apple

To build and install the MSSQL extension, in Terminal change to the new MSSQL extension directory (php-5.4.17/ext/mssql) and run the below commands to build the mssql extension.

To build and install the PDO_DBLIB extension, in Terminal change to the new PDO_DBLIB extension directory (php-5.4.17/ext/pdo_dblib) and run the below commands to build the pdo_dblib extension.

Now that thats done all we need to do is make changes to the php.ini file so that the extensions are enabled. The file we need to edit is /etc/php.ini, if your system doesn’t have this file then lets create it from the default one.

ONLY RUN THIS IF YOUR SYSTEM DOESN’T ALREADY HAVE A /etc/php.ini

Ok so at this stage we can edit the /etc/php.ini file, as there are many ways to do this I will describe the process rather than listing commands.

  • Open /etc/php.ini in your favourite text editor with root privileges
  • Search for the line ; extension_dir = "./"
  • Replace the above line with extension_dir = "/usr/lib/php/extensions/no-debug-non-zts-20100525/"
  • Search for the line ;extension=php_zip.dll
  • Below this line add these two lines:
  • extension=mssql.so
  • extension=pdo_dblib.so
  • Save the file and exit

The changes will be immediate for PHP CLI but if you are using PHP with Apache you will need to restart Apache (sudo apachectl restart).

Hope it works for you…

9 thoughts on “PHP MSSQL & PDO_DBLIB (FreeTDS) support on Mac OSX 10.9 Mavericks

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: