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

Home / Mac / 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…

8 Comments

  • generalconsensus

    Unfortunately you freetds setup was not recognized by either the ext/mssql or ext/pdo_dblib configure command. Possible the issue was that I have a x64 setup — but i really don’t know. It kept complaining of a missing freetds folder, a missing lib folder in freetds, etc…

    In any case I used brew install freetds on Mavericks to overcome this and than reimplemented your configure command as “./configure –with-php-config=/usr/bin/php-config –with-mssql=/usr/local/Cellar/freetds/0.91/” and it worked just fine.

    Thanks!

  • you first set FreeTDS directory to /private/etc/freetds but then use it in your extension configure command as /usr/local/freetds, which didn’t work for me.

  • I followed this step by step and I still can not get the .so extensions to load. They do not show in my phpinfo. I checked the files were in the correct directories. I am using the correct php.ini file and I got no errors during the install process. I’m at and end. Any suggestions?

Leave a Reply

%d bloggers like this: