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:
1 2 3 |
./configure make sudo make install |
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.
1 2 3 |
./configure --prefix=/usr/local/freetds --with-tdsver=8.0 --sysconfdir=/usr/local/freetds/conf make sudo make install |
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.
1 2 3 4 |
phpize ./configure --with-php-config=/usr/bin/php-config --with-mssql=/usr/local/freetds/ make sudo cp modules/mssql.so /usr/lib/php/extensions/no-debug-non-zts-20100525/ |
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.
1 2 3 4 |
phpize ./configure --with-php-config=/usr/bin/php-config --with-pdo-dblib=/usr/local/freetds/ make sudo cp modules/pdo_dblib.so /usr/lib/php/extensions/no-debug-non-zts-20100525/ |
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
1 |
cp /etc/php.ini.default /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…
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.
Good spot, thanks. I have amended the post.
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?
I have the same problem as you. Hope this gets some answers.
Unable to connect: Adaptive Server is unavailable or does not exist (severity 9), any idia about this ?
Not really. All I can say is check your config in the freetds config file /usr/local/freetds
Since this morning i am on this probleme. I have just solved the problem. I put in “/usr/local/freetds/conf/freetds.conf” some data about the host :
[MYHOSTIP_or_domain]
host : MYHOSTIP_or_domain
port = 1433
[global]
tds version = 7.0
Thx for your useful tutorial
This link stackoverflow helped me: http://stackoverflow.com/a/19951183/4469644
[…] http://blog.andyhunt.info2013/11/29/php-mssql-pdo_dblib-freetds-support-on-mac-osx-10-9-mavericks/ […]