Install a PHP Extension using PECL
MAMP PRO provides all the requirements to install PHP extensions via PECL. This guide uses the mongodb extension and PHP 8.0.2 as an example.
-
Open MAMP PRO and click on PHP in the Languages sidebar section.
-
Set PHP 8.0.2 as the Default version.
-
Enable Activate command line shortcuts for the selected PHP version.
-
Restart the servers. A
peclalias is now added to~/.profile,.profile, and.zprofile. -
Open Terminal (
/Applications/Utilities/Terminal.app). -
Change to the PHP binary directory:
cd /Applications/MAMP/bin/php/php8.0.2/bin -
Install the extension:
pecl install mongodb -
If you see
Cannot find autoconf, install it first:curl -OL http://ftpmirror.gnu.org/autoconf/autoconf-latest.tar.gztar xzf autoconf-latest.tar.gzcd autoconf-*./configure --prefix=/usr/localmakesudo make installThen return to the PHP directory and retry:
cd /Applications/MAMP/bin/php/php8.0.2/binpecl install mongodbA successful build ends with output like:
Build process completed successfullyInstalling '.../mongodb.so'install ok: channel://pecl.php.net/mongodb-1.9.1 -
Verify that
mongodb.sois in/Applications/MAMP/bin/php/php8.0.2/lib/php/extensions/no-debug-non-zts-20200930/. -
Open the PHP 8.0.2 template via File › Open Template › PHP (php.ini) › 8.0.2 and add:
extension=mongodb.so
-
Save and close the template.
-
Make sure the host you want to use is set to PHP 8.0.2.
-
Restart the servers and verify the extension is loaded via
phpinfo().