How to install gmp extension for php 7.2 using MAMP on OSX
Asked Answered
M

3

20

How to install gmp extension for php 7.2.1 using MAMP on OSX?

I'm trying to encrypt a token with php and this library(lcobucci/jwt) using the Elliptic Curve Digital Signature Algorithm (ECDSA) with the P-256 curve and the SHA-256 hash algorithm.

error when running php script:

Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_ERROR)
Class 'Mdanter\Ecc\EccFactory' not found

I figured that I'm missing the mdanter/ecc dependicy package, so I tried running the following command.

command running:

composer require mdanter/ecc

output:

mdanter/ecc v0.5.0 requires ext-gmp * -> the requested PHP extension gmp is missing from your system

I've tried everything I could find researching this error and related to MAMP. But I couldn't solve this problem. Is there anyone here who has experience in adding the gmp php extension to MAMP specificly and is willing to help me out?

Note: I'm not a very experienced web developer, I mostly create iOS apps and I want to generate a token in php, so I can access the Apple Music Kit API resources.

Madox answered 20/5, 2018 at 13:42 Comment(1)
Please someone has a response ? I tried everything but nothing is up to date ...Addressograph
G
21

Here is how i did in 2020

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

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)

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.4.1/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 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 :)

Posted here with screenshots, https://mycodde.blogspot.com/2020/01/install-php-gmp-extension-in-mamp-2020.html

Gastongastralgia answered 30/1, 2020 at 8:50 Comment(2)
This should be the accepted answer imho. Thanks, it's the only solution that worked for me.Derr
I wrote the answer. And It helped me after an Year when i had same question :)Gastongastralgia
D
16

you have to build the gmp extension from the php source code.

you need Xcode and homebrew, to install compiler toolchain, gmp lib and autoconf:

brew install autoconf gmp

as my MAPP is shipped with php 7.2.8, I would use this php version as example, you could upgrade your MAPP installation or replace version related to 7.2.1. Download and unpack php(7.2.8) source code to a dir, then config the build environment against your php installation and build the extension:

cd ext/gmp
/Applications/MAMP/bin/php/php7.2.8/bin/phpize
./configure --with-php-config=/Applications/MAMP/bin/php/php7.2.8/bin/php-config
make
make install

add the extension loading config to php.ini in /Applications/MAMP/bin/php/php7.2.8/conf:

extension=gmp.so

now this would work:

/Applications/MAMP/bin/php/php7.2.8/bin/php composer.phar require mdanter/ecc
Damal answered 28/9, 2018 at 9:3 Comment(3)
above 4 line commads not working for me , my GMP is installed in /usr/local/Cellar/gmp/6.1.2_2 , this commands /Applications/MAMP/bin/php/php7.2.8/bin/phpize ./configure --with-php-config=/Applications/MAMP/bin/php/php7.2.8/bin/php-config not working :(Unmentionable
those commands(paths) are for MAMP installation, not homebrew.Damal
@SaurabhMistry - you need to download a fresh version of 7.2.8 from the link in the description (php.net/get/php-7.2.8.tar.bz2/from/a/mirror) and then run the terminal commands from the ext/gmp folder in that fresh version.Handout
C
0

I ran into the error unable to locate gmp.h while running the configure command

I had to use the --with-gmp tag in order to tell the good path to gmp.

./configure --with-php-config=/Applications/MAMP/bin/php/php7.2.34/bin/php-config --with-gmp=/opt/homebrew/Cellar/gmp/6.2.1
Cosenza answered 20/3, 2021 at 16:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.