How to install PHP, Pear, PECL, and APC with Homebrew on Mac OS X?

I'm trying to install APC for PHP 5.3 in the easiest way possible. I love Homebrew so I started down that route. I was able to install PHP 5.3.6 with this command:

brew install https://github.com/adamv/homebrew-alt/raw/master/duplicates/php.rb --with-mysql

I think this is supposed to install PHP, Pear, and PECL. It seems to install these just fine.

Now when I try to install APC:

$ pecl install apc
downloading APC-3.1.9.tgz ...
Starting to download APC-3.1.9.tgz (155,540 bytes)
.................................done: 155,540 bytes

Warning: require_once(Archive/Tar.php): failed to open stream: No such file or directory in PackageFile.php on line 305

Warning: require_once(Archive/Tar.php): failed to open stream: No such file or directory in /usr/local/Cellar/php/5.3.6/lib/php/PEAR/PackageFile.php on line 305

Fatal error: require_once(): Failed opening required 'Archive/Tar.php' (include_path='/usr/local/Cellar/php/5.3.6/lib/php') in /usr/local/Cellar/php/5.3.6/lib/php/PEAR/PackageFile.php on line 305

How can I fix this?


Solution 1:

Now homebrew-php has been migrated to homebrew-core and by default, PECL should be installed along with your PHP.

Here are the suggested steps:

  1. Reinstall PHP via: brew install php.
  2. Check pecl command by: which -a pecl.

To see which files were installed, see: brew list php.

To install PHP extensions, you need to use PECL as a recommended way.

With the migration to Homebrew-core the php formula has stopped taking over the role of PECL. Installing xdebug can (and should) be done through PECL. Source: GH-26007

For example: pecl install apc or pecl install xdebug.

If you've got some problem installing the extension, you need to report it to its maintainer. Check PECL website for more details.

Solution 2:

pecl and pear are provided with Homebrew's version of PHP:

brew install php
pecl install apcu

If you're weary that pecl and pear are provided by php, try this:

ls -al $(which pecl)
ls -al $(which pear)

Both locations should symlink to Cellar/php/...

Note, macOS provides a php version which is generally behind that of Homebrew. To make sure you're running the Homebrew version, prefix your php commands with $(brew --prefix php)/bin.

Example for Composer:

$(brew --prefix php)/bin/php composer.phar install

The reason this is important is because common extensions -- such as ext-intl and ext-gettext are provided automatically and will fix these automatically.

Notice, for php-fpm, use brew reinstall php --with-fpm. The php-fpm path will be... $(brew --prefix php)/sbin/php-fpm.

Solution 3:

Below command should help

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