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

@jonothedev
Copy link

jonothedev commented Jul 11, 2019

Thanks for this, you forgot to include the 'make' command after you run configure.

### 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

@pwd-anderson
Copy link

top merci

@jschroed91
Copy link
Author

@jonojamesmac Saw your note just now for some reason, I updated the gist to include the make command. Thank you!

@givihuda
Copy link

givihuda commented Apr 18, 2021

This doesn't work with MAMP Pro v6.3.7 with PHP 5.6.40 installed on macOS Catalina (fresh install) because phpize uses the Mac's /usr/bin/phpize and a bunch of other /usr files that are probably newer than yours... I just get a bunch of warnings and errors with the ./configure command while in the folder and the make command, and no .so file is generated.

I'm honestly scratching my head as how you got any of this to work, unless your non-MAMP non-PHP 5 files that were run within the commands (like the native pre-installed Mac PHP 7.x and related files) were close enough to PHP 7.1 requirements that it just worked, and that's the only way it will work.

I'm not sure that I need to overwrite all of those /usr file references to older versions (which I don't want to do), and brew just simply doesn't support a lot of libraries that are deprecated... so I could be in a labyrinth of wild goose chases, which it already feels like I am, and I'm afraid I'll screw up my system so bad with old software that I'll just create new problems. Not sure what to do here.

@jschroed91
Copy link
Author

@givihuda Bummer! Sorry to hear that it's not working for you now. It looks like someone was able to use this Dec 22, 2020 but I can't speak to their current system / how up to date they are.

This was originally written on Jan. 9th, 2019 - I have not tested it since then, and the only update I've made was to include the make command added in the comment above (I personally didn't have to run the make command if I recall correctly, or I did but didn't include it originally and forgot that I had to run it).

If you end up resolving this issue using another method it would be very appreciated if you circled back here and posted the solution so that I can leave a comment at the top of this gist with that information.

@givihuda
Copy link

givihuda commented May 6, 2021

@jschroed91 Did you run the commands with native PHP 7.x installed? The difference in your and my outcomes seems to be what you had natively on the computer at the time, at least some of them. That's a typical problem with people trying to get old software to work; one person's dependencies end up having different results when run because of newer software at the time.

I haven't found a solution to this other than running the PHP framework's built-in php server command (bin/console server:start in my case, with Symfony), and I had to uninstall brew PHP 5.6 due to composer getting stuck on it no matter what I did with brew or .zshrc or PATH or aliases or anything... I'm still scratching my head at this, though I'm assuming compiling old PHP 5.6 library dependencies, and maybe even re-compiling PHP 5.6 right along with it, would solve it, but that seems like a bigger gamble.

My biggest concern with getting old software to work on newer computers is ending up downgrading software on the computer that other things use.

@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