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.
- 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
You'll need to install these two things via homebrew:
$ brew install autoconf
$ brew install freetds
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
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"
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
$ cd ~/Downloads
$ tar -zxf php-7.1.20.tar.gz
$ 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 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:
$ 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 ;
;;;;;;;;;;;;;;;;;;;;;;
$ 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.
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.
This was pretty helpful, although wouldn't work for MAMP: https://github.com/BellevueCollege/public-docs/blob/master/PHP/configure-mssql-pdodblib-mac.md
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.