Skip to content

Instantly share code, notes, and snippets.

@jschroed91
Last active October 6, 2023 13:57
Show Gist options
  • Save jschroed91/8235909e16f79fbb31feff1f313aa9ca to your computer and use it in GitHub Desktop.
Save jschroed91/8235909e16f79fbb31feff1f313aa9ca to your computer and use it in GitHub Desktop.
Installing pdo-dblib + freeTDS with MAMP 5 and php 7.1 on macOS

macOS pdo-dblib and freetds with MAMP 5

Note that this was written Jan 9th, 2019, and I personally have not tested this since then. It's possible it will still work for your machine, but I can't guarantee it.

Based on some comments, it looks like someone may have had success with it Dec 22, 2020 too.

Prerequisites

  • This was tested with MAMP 5, but probably works with other versions
  • This was tested with php 7.1.20 that was installed via MAMP interface
  • You will need to use Homebrew for part of this - no, you won't need to use homebrew for your php or apache or anything. you'll still use MAMP. It's just used to install some things we'll need to compile pdo_dblib

Someone says you should ensure you have the latest xcode (or install it) with the command line tools.

I didn't check or run this, but I've had it installed somewhat recently. May as well run it

$ xcode-select ---install

Install deps with homebrew

You'll need to install these two things via homebrew:

$ brew install autoconf
$ brew install freetds

pecl config location?!

I don't think these 2 pecl commands are required probably... but I did run them during this process while messing around with things, and everything ended up working for me... so... let's run them just to be safe.

First command tells pecl where your MAMP's php.ini file is, and the second command installs PDO via pecl... because why not.

$ pecl config-set php_ini /Applications/MAMP/bin/php/php7.1.20/conf/php.ini
$ pecl install pdo

Is the php-cli using your MAMP php version too?

If not, alls you gotta do is add this towards the beginning of your $PATH:

/Applications/MAMP/bin/php/php7.1.20/bin

I use fish shell, so for me I just ran:

$ echo 'set -g fish_user_paths "/Applications/MAMP/bin/php/php7.1.20/bin" $fish_user_paths' >> ~/.config/fish/config.fish

For bash, you'd add something similar to your ~/.profile or ~/.bash_profile file:

export PATH="/Applications/MAMP/bin/php/php7.1.20/bin:$PATH"

Build the pdo-dblib library from php source

Download php source for your MAMP's php version (7.1.20 in this example)

Download php source from a mirror here (change the php version if yours is different):

http://us1.php.net/get/php-7.1.20.tar.gz/from/a/mirror

Then, extract the source

$ cd ~/Downloads
$ tar -zxf php-7.1.20.tar.gz

Compile the pdo_dblib and copy to MAMP

$ cd php-7.1.20/ext/pdo_dblib
$ phpize

### compile using MAMP's php config/version
$ ./configure --with-php-config=/Applications/MAMP/bin/php/php7.1.20/bin/php-config  --with-pdo-dblib=/usr/local/
$ make

### hooray! if you got here without an error, it worked. Now, copy the compiled extension over to MAMP's extension dir.
$ cp modules/pdo_dblib.so /Applications/MAMP/bin/php/php7.1.20/lib/php/extensions/no-debug-non-zts-20160303/

Add the extension to your MAMP php configuration files

Add this to your MAMP's web php.ini file. You will add it within the "Dynamic Modules" section of the file. You can open the file and edit it right through MAMP's GUI.

; add this line to MAMP's php.ini file
extension=pdo_dblib.so

Save and close - it'll ask you if you want to restart, say yes.

Here's a gif that may or may not work:

jan 9 2019 11_15 pm - edited

Then, add it to your cli too:
$ nano /Applications/MAMP/bin/php/php7.1.20/conf/php.ini

I came across some note that told me I should it OUTSITE the "Dynamic Extensions" block otherwise it may get overwritten... I have no clue how accurate that is, but I heed their warning.

So I put mine literally right above the Dynamic Extensions block like:

extension=pdo_dblib.so

;;;;;;;;;;;;;;;;;;;;;;
; Dynamic Extensions ;
;;;;;;;;;;;;;;;;;;;;;;

Confirm the extension is loaded!

Confirm it's loaded for your php cli on command line

$ php -m | grep pdo_dblib

You should see a line output with "pdo_dblib"! If you don't see it, then you might not have the MAMP cli set up on your $PATH in your shell.

Confirm it's loaded on your MAMP web server

MAMP has a way to view the phpinfo(); output don't they? if not, throw <?php phpinfo(); into a php file on your mamp's site and hit it in your browser.

References / Other Info

This was pretty helpful, although wouldn't work for MAMP: https://github.com/BellevueCollege/public-docs/blob/master/PHP/configure-mssql-pdodblib-mac.md

@ismailkoksal
Copy link

I have freetds installed with Homebrew in my M1 Mac
Running ./configure --with-php-config=/Applications/MAMP/bin/php/php5.6.40/bin/php-config --with-pdo-dblib=/opt/homebrew/Cellar/freetds/1.4.2 worked

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment