Install PHP gmp Extension in MAMP - 2020

Following instructions are for MAMP users only.

Step 1:
Check if you already have gmp is available in MAMP php

/Applications/MAMP/bin/php/php7.4.1/bin/php -i | grep gmp
Above command should print phpinfo in terminal, searching for gmp in phpinfo. If gmp not already available it returns nothing in terminal.


Step 2:
Download php from source https://github.com/php/php-src/releases pick the version which is matching with MAMP PHP version you have.

Step 3:
Copy the extension you want. Here we are copying gmp directory.



Paste it to /Applications/MAMP/bin/php/php7.4.1/include/php/ext

(Make sure to move to your MAMP php version directory)

Step 4:
Just cd into the extension gmp directory


cd /Applications/MAMP/bin/php/php7.4.1/include/php/ext/gmp

Then run phpize command


/Applications/MAMP/bin/php/php7.4.1/bin/phpize


Step 5:

./configure --with-php-config=/Applications/MAMP/bin/php/php7.2.8/bin/php-config

It outputs following


Then

make


Then

make install




Its installed now.

You can confirm it by


/Applications/MAMP/bin/php/php7.4.1/bin/php -i | grep gmp

gmp
gmp support => enabled

If you didn't see gmp support enabled, you may need to add following to php.ini.

This command will show you which php.ini file is used by MAMP php

 /Applications/MAMP/bin/php/php7.4.1/bin/php -i | grep "php.ini"


Add extension=gmp.so




Restart MAMP :)

16 Comments

  1. Hi! I was able to install gmp so I could install phpipam on my MAMP installation. There's only a few things I'd add:

    In step 4, I was getting "Cannot find autoconf" after the phpize command. If you do too, just install autoconf from brew: brew install autoconf. If not, you won't be able to configure for compilation. Also if your computer doesn't have the xcode commandline tools, you can install it by executing: xcode-select --install.

    In step 5, remember to change the version number to php7.4.1 in the directory (or whatever version's current)

    Thanks so much for the guide.

    ReplyDelete
    Replies
    1. For MAC users, this is required if there is any xcode update received recently.

      Delete
  2. Install fails when running php configure command, it returns:
    configure: error: GNU MP Library version 4.2 or greater required.
    On MacBook Pro with M1 chip (ARM).

    ReplyDelete
    Replies
    1. I was able to fix this issue by downloading the GNU MP Library directly from https://gmplib.org/#DOWNLOAD after installing this, the php configure command works.

      Delete
  3. Thank you for the help

    ReplyDelete
  4. I tried everything but till getting:
    checking for __gmp_version in -lgmp... no
    configure: error: Unable to load libgmp
    I also tried brew reinstall libmpd, but no luck

    ReplyDelete
Previous Post Next Post