Installing pecl and pear on OS X 10.11 El Capitan, macOS 10.12 Sierra, macOS 10.13 High Sierra (< 10.13.3)

Solution 1:

There's a much easier way — no need to disable SIP or download your own copy:

sudo php /usr/lib/php/install-pear-nozlib.phar -d /usr/local/lib/php -b /usr/local/bin

Solution 2:

You shouldn't install binaries into system /usr, use /usr/local instead.


The pecl and pear commands should come along with PHP when installing via Homebrew.

Here is the example installing PHP with the latest Homebrew:

brew install php

or the specific version:

brew install [email protected]
brew install [email protected]

To find your pecl and pear commands, run:

find -L "$(brew --prefix php)" -name pecl -o -name pear

or:

find -L "$(brew --prefix [email protected])" -name pecl -o -name pear

If you don't have it, consider uninstalling previous PHP version or run reinstall instead.

You can also try to relink it by:

brew unlink [email protected] && brew link [email protected] --dry-run && brew link --overwrite --force [email protected]

Otherwise, link it manually:

ln -vs "$(find -L "$(brew --prefix [email protected])/bin" -name pecl)" /usr/local/bin
ln -vs "$(find -L "$(brew --prefix [email protected])/bin" -name pear)" /usr/local/bin

Alternatively download Pear it directly as a Phar package:

curl -o /usr/local/bin/pear http://pear.php.net/go-pear.phar
chmod +x /usr/local/bin/pear

or with this following one-liner (will work on Linux, but not on Unix):

curl -sL http://pear.php.net/go-pear.phar | sudo install -v -m755 /dev/stdin /usr/local/bin/pear