Install a PHP Extension using PECL

MAMP PRO provides you with all the requirements to install PHP Extensions using PECL. This guide shows you how to install a PHP Extension via PECL using the mongodb extension and PHP 8.0.2 as an example.

  1. Open MAMP PRO and click on the “PHP” entry in the sidebar in the “Languages” area.
  2. Select the PHP version as “Default version” with which you want to use the MongoDB Extension.
  3. Activate the “Activate command line shortcuts for the selected PHP version, pear & pecl” checkbox.
  4. Restart your servers. A PECL alias now exists in your “~/.profile”, “.profile” and “.zprofile” file.
  5. Open the Terminal app (/Applications/Utilities). Tip: If you have already opened the Terminal app, then you must close and reopen it for the changes to the configuration files “~/.profile”, “.profile” and “.zprofile” to take effect.
  6. Change to the “/Applications/MAMP/bin/php/php8.0.2/bin” directory.
    cd /Applications/MAMP/bin/php/php8.0.2/bin
  7. Enter the following command and confirm your entry with Enter.
    pecl install mongodb
  8. If you are shown the message “Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable. Then, rerun this script.”, then you need to perform the following steps:

    1. Enter the following commands in the Terminal and confirm each command with Enter. The asterisk at the command autoconf-* stands for the corresponding version number (for example “2.71”).

      curl -OL
      tar xzf autoconf-latest.tar.gz
      cd autoconf-*
      ./configure --prefix=/usr/local
      sudo make install
    2. Use the following commands in the Terminal to switch back up one directory level and restart the PHP extension installation process:

      cd ..
      pecl install mongodb
    3. Your PHP Extension should now build and you should see the following result:

      Build process completed successfully
      Installing '/Applications/MAMP/bin/php/php8.0.2/lib/php/extensions/no-debug-non-zts-20200930/'
      install ok: channel://
      configuration option "php_ini" is not set to php.ini location
      You should add "" to php.ini
  9. A “” extension should now be in your “/Applications/MAMP/bin/php/php8.0.2/lib/php/extensions/no-debug-non-zts-x” folder.
  10. Switch back to MAMP PRO and select “8.0.2” from the “File > Open Template > PHP (php.ini)” menu.
  11. The template for the php.ini file of PHP version 8.0.2 is opened. Insert the following line into it:

    MAMP PRO - Install a PHP extension using PECL - Add extension to php.ini file

  12. Save and close the template.
  13. Please make sure that the host you want to use is also set to the appropriate PHP version for which you have installed the PHP extension - in our case this is PHP 8.0.2.
  14. Restart your servers and verify the extension has been loaded by checking phpInfo.
    MAMP PRO - Install a PHP extension using PECL - phpInfo