First of all install we need to install PEAR:

curl -O  http://pear.php.net/go-pear.phar
php -d detect_unicode=0 go-pear.phar

The installation will suggest to set up some directories:

Below is a suggested file layout for your new PEAR installation.  To
change individual locations, type the number in front of the
directory.  Type 'all' to change all of them or simply press Enter to
accept these locations.

 1. Installation base ($prefix)                   : /Users/serega/pear
 2. Temporary directory for processing            : /tmp/pear/install
 3. Temporary directory for downloads             : /tmp/pear/install
 4. Binaries directory                            : /Users/serega/pear/bin
 5. PHP code directory ($php_dir)                 : /Users/serega/pear/share/pear
 6. Documentation directory                       : /Users/serega/pear/docs
 7. Data directory                                : /Users/serega/pear/data
 8. User-modifiable configuration files directory : /Users/serega/pear/cfg
 9. Public Web Files directory                    : /Users/serega/pear/www
10. System manual pages directory                 : /Users/serega/pear/man
11. Tests directory                               : /Users/serega/pear/tests
12. Name of configuration file                    : /Users/serega/.pearrc

1-12, 'all' or Enter to continue:

I’ve used the default settings and pressed Enter. Then next step is to add PEAR to your PATH. I use Oh My Zsh and my PATH settings are located in ~/.zshrc file:

# Pear
# -----------------------------------------------------------------------------
export PATH="/Users/serega/pear/share/pear:$PATH"
export PATH="/Users/serega/pear/bin:$PATH"

To check your installation run:

pear version

If the installations was successful the output will be similar to the following:

PEAR Version: 1.10.1
PHP Version: 7.0.12
Zend Engine Version: 3.0.0
Running on: Darwin MacBook-Air-Sergej.local

Then there are two steps to install any extension:

  1. Run pecl install *extension_name*
  2. Add appropriate *.so file to your php.ini