FAQ > PHP

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. Activate the “Activate command line shortcuts for the selected PHP version, pear & pecl” checkbox.
  3. Restart your servers. A PECL alias now exists in your “~/.profile”, “.profile” and “.zprofile” file.
  4. 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.
  5. Change to the “/Applications/MAMP/bin/php/php8.0.2/bin” directory.
    cd /Applications/MAMP/bin/php/php8.0.2/bin
    
  6. Enter the following command and confirm your entry with Enter.
    pecl install mongodb
    
  7. 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 http://ftpmirror.gnu.org/autoconf/autoconf-latest.tar.gz
      tar xzf autoconf-latest.tar.gz
      cd autoconf-*
      ./configure --prefix=/usr/local
      make
      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/mongodb.so'
      install ok: channel://pecl.php.net/mongodb-1.9.1
      configuration option "php_ini" is not set to php.ini location
      You should add "extension=mongodb.so" to php.ini
      
  8. A “mongodb.so” extension should now be in your “/Applications/MAMP/bin/php/php8.0.2/lib/php/extension/no-debug-non-zts-x” folder.
  9. Switch back to MAMP PRO and select “8.0.2” from the “File > Open Template > PHP (php.ini)” menu.
  10. The template for the php.ini file of PHP version 8.0.2 is opened. Insert the following line into it:
    extension=mongodb.so
    

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

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