Need your OS X-hosted PHP code to talk to Microsoft SQL Server? Here’s the guide I couldn’t find when I needed it.
Or you could just download my Mavericks-ready mssql.so and skip to the end.
Update (6 July 2014): A newer mssql.so compiled for PHP 5.4.24 on Mavericks 10.9.4 can be downloaded here.
Update (22 December 2014): A newer mssql.so compiled for PHP 5.5.14 on Yosemite 10.10.1 can be downloaded here.
Update (16 September 2015): A newer mssql.so compiled for PHP 5.5.27 on Yosemite 10.10.5 can be downloaded here.
- Xcode with command line tools (these are installed when you first run Xcode, as of the latest version)
- Latest autoconf source from http://ftp.gnu.org/gnu/autoconf/ (or Homebrew installed)
- Latest FreeTDS source from http://www.freetds.org/ (or Homebrew installed)
- Source for the same version of PHP that ships with OS X (5.4.17 on 10.9; run `php -v` from a terminal if unsure)
Build and install autoconf
If you’re a Homebrew user,
brew install autoconf is easier than the following.
$ tar zxf autoconf-latest.tar.gz
$ cd autoconf-2.69
$ sudo make install
Build and install FreeTDS
FreeTDS is on Homebrew too:
brew install freetds
$ tar zxf freetds-stable.tgz
$ cd freetds-0.91
$ sudo make install
Build and install mssql.so
Don’t worry, unlike some of the Internets will tell you, there’s no need to rebuild PHP itself. Nor do you need to write an essay after
Update (16 September 2015): phpize doesn’t seem to work out-of-the box anymore. If it can’t find the files it needs (you’ll see grep errors), try adding a symbolic link like this:
sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/php /usr/include/php
$ tar zxf php-5.4.17.tar.gz
$ cd php-5.4.17/ext/mssql
$ ./configure --with-php-config=/usr/bin/php-config --with-mssql=/usr/local/
$ sudo cp modules/mssql.so /usr/lib/php/extensions/no-debug-non-zts-20100525/
Finally, add this line to your
php.ini (probably in
And restart Apache if necessary.