So it looks like the new 'System Integrity Protection' lockdown of /usr (among other directories) makes pear and pecl a non-starter. Has anyone found a workaround short of disabling it?
-
In the end, I disabled it, did what I needed to do, then re-enabled it. – axlotl Oct 01 '15 at 21:36
-
1How do you disable and renable it? – Aegis Oct 02 '15 at 09:02
-
Here's a link to a Macworld article that describes how to enable and disable 'System Integrity Protection.' http://www.macworld.com/article/2986118/security/how-to-modify-system-integrity-protection-in-el-capitan.html – RichardD Oct 02 '15 at 12:00
10 Answers
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

- 12,531
- 4
- 41
- 63
-
Took a while to accept because I didn't need this again until I installed Sierra and borked my whole LAMP stack (again). – axlotl Oct 10 '16 at 16:26
-
3This works great! But when I try to install an extension with `sudo pecl install` I get: `ERROR: failed to write /usr/lib/php/extensions/...` How can I get around this? – John J. Camilleri Oct 11 '16 at 08:05
-
John: try this http://stackoverflow.com/questions/26584599/changing-pecl-installation-directory – Paul Schreiber Oct 11 '16 at 13:27
-
-
Those are command-line flags specifying the path to (a) the PHP binary and (b) where pear should be installed. – Paul Schreiber Feb 21 '18 at 14:21
-
29This is not working with macOS High Sierra version 10.13.3 `Could not open input file: /usr/lib/php/install-pear-nozlib.phar` – kekko12 Apr 11 '18 at 10:22
-
3Also not working for Mohave: `Could not open input file: /usr/lib/php/install-pear-nozlib.phar` – Daniel Flippance Mar 22 '19 at 22:32
-
This should work `curl -s -O https://pear.php.net/install-pear-nozlib.phar` `sudo php install-pear-nozlib.phar -d /usr/local/lib/php -b /usr/local/bin` – Gampesh Apr 05 '19 at 10:50
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 php@7.1
brew install php@5.6
To find your pecl
and pear
commands, run:
find -L "$(brew --prefix php)" -name pecl -o -name pear
or:
find -L "$(brew --prefix php@7.1)" -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 php@7.1 && brew link php@7.1 --dry-run && brew link --overwrite --force php@7.1
Otherwise, link it manually:
ln -vs "$(find -L "$(brew --prefix php@7.1)/bin" -name pecl)" /usr/local/bin
ln -vs "$(find -L "$(brew --prefix php@7.1)/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

- 155,785
- 88
- 678
- 743
-
2@GregoryBell Thanks for a good catch. Installing PHP with `--with-pear` should install pear correctly (in `/usr/local/opt/php56/bin/pear`). Then `brew link php56` will link its binary to `/usr/local/bin/pear`. – kenorb Apr 19 '16 at 09:01
-
1I had to use `brew unlink php56 && brew link php56 --dry-run && brew link --overwrite php@5.6 --force` in order for it to work, I had an older php 5.5 install that had some conflicts. – Juan Stiza Jul 17 '18 at 13:12
From this link: http://jason.pureconcepts.net/2012/10/install-pear-pecl-mac-os-x/ With this instructions, you don't need to disable 'System Integrity Protection'
The following instructions install PEAR and PECL on Mac OS X under /usr/local/. PECL is bundled with PEAR. So this is as simple as installing PEAR on Mac OS X.
PEAR is PHP’s Package Repository and makes it easy to download and install PHP tools like PHPUnit and XDebug. I specifically recommend these two for every PHP developer.
Download PEAR
curl -O https://pear.php.net/go-pear.phar sudo php -d detect_unicode=0 go-pear.phar
Configure and Install PEAR
You should now be at a prompt to configure PEAR.
- Type 1 and press return.
Enter:
/usr/local/pear
Type 4 and press return.
Enter:
/usr/local/bin
Press return
Verify PEAR.
You should be able to type:
pear version
Eventually, if you use any extensions or applications from PEAR, you may need to update PHP’s include path.

- 6,177
- 2
- 22
- 39

- 1,338
- 1
- 16
- 24
On Mohave I had to run the following commands - thanks go to https://tobschall.de/2018/08/07/pear-on-mojave/
cd /tmp
curl -s -O https://pear.php.net/install-pear-nozlib.phar
sudo php install-pear-nozlib.phar -d /usr/local/lib/php -b /usr/local/bin

- 7,734
- 5
- 42
- 55
High Sierra setup:
- install Brew
- install PHP with Brew
There is preinstalled PEAR PACKAGE in
/usr/local/opt/php@<your_version>/bin
from there you can run
pecl install xdebug
and you should have working PHP binary with Xdebug.

- 185
- 4
- 14
-
@frumbert I know it's probably really late but you can start script file from same folder using following syntax `./pecl install xdebug`. I hope it can help someone. – Najdan Tomić Feb 08 '19 at 00:11
This worked for me as of MacOS Sierra 10.12.1 for upgrading PHP, installing PEAR and V8
brew tap homebrew/dupes
brew tap homebrew/versions
brew tap homebrew/homebrew-php
phpversion="$(php -v | tail -r | tail -n 1 | cut -d " " -f 2 | cut -c 1,3)"
brew unlink php$phpversion
brew install php71
brew install autoconf
curl -O http://pear.php.net/go-pear.phar
php -d detect_unicode=0 go-pear.phar
echo -e "\nexport PATH=$HOME/pear/bin:$PATH \n"
source ~/.bash_profile
echo -e "\ninclude_path = '.:/Users/YOURUSERNAME/pear/share/pear/' \nextension=v8js.so \n" >> /usr/local/etc/php/7.1/php.ini
git clone https://github.com/phpv8/v8js ~/tmp/v8js && cd $_
./configure CXXFLAGS="-Wno-c++11-narrowing"
make
make test
make install
sudo apachectl restart

- 34,416
- 17
- 114
- 136
Add suffix --with-pear
to install pear and pecl
See example below
brew install php --with-pear
brew reinstall php --with-pear

- 1,010
- 13
- 13
When brew is used and not linked, use:
brew install php@5.6
brew unlink php@5.6
$(brew --prefix php@5.6)/bin/pecl
$(brew --prefix php@5.6)/bin/pear

- 1,883
- 3
- 23
- 17
For macOS Mojave 10.14.4 just use /local instead of /usr when asked for "Installation base ($prefix)" location.

- 191
- 1
- 4