Quick fix for the phpseclib -> BigInteger choke on macOS 10.14

This will be quick.

You are tooling with phpseclib on macOS. You try generating some hefty, say 4096 bit keypairs and BigInteger times out after 60 seconds. WTF do you do?

Well, BigInteger.php will leverage OpenSSL and/or bcmath for this kind of stuff, but it seems it gets a migraine after 2048 bits. It’ll charge after mcrypt and gmp too, if they are available, but neither is in macOS’s default PHP. We’ve covered mcrypt in the recent (and many days) past, and I had it and libsodium installed on my “device” when I filled an Apache error log up with fatals. Hence I looked to get gmp running.

It’s a relatively simple process … first gather all the items listed in this post on installing mcrypt. Then, you are going to follow some simple steps.

Via Terminal

You are hitting brew first:

$ brew install autoconf pkg-config
$ brew install gmp

Then, get into the directory where the php-7.1.23 source code download resides and type this:

$ tar -zxvf php-7.1.23.tar.gz

Now grab the header files for macOS. You do that by typing the following (all one line please):

$ sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /

Next, hop into to the php-7.1.23/ext/gmp/ post-“unzipping”, and type these commands, one by one while giving each step time to complete:

$ phpize
$ ./configure
$ make
$ make test
$ sudo make install

Almost there

Navigate to /etc, and find the php.ini file. If you only see php.ini.default, rename that puppy to php.ini. Then open it and look for …

enable_dl = On

Add one line in the Dynamic Extensions section …


PHP is likely enabled, meaning I hope you are not doing this shit for amusement, nevertheless if it isn’t open the /etc/apache2/httpd.conf file and remove the “#” from in front of …

LoadModule php7_module libexec/apache2/libphp7.so

Save and close.

Finally, restart Apache with …

$ sudo apachectl start

… and point your browser to a file that contains the following:

<?php phpinfo(); ?>

You should see this at the top:

And this just down below:

Does it solve the BFMP (big f**king math problem)?

MG signing off (with a yep, in milliseconds)

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.