pecl 绑定于 pear

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.

 

Mac OS X 安装 pecl

Mac下通过brew安装php5.6,发现缺少pecl,于是开始安装。

pecl 不要安装在目录 /usr/lib/php/ 下,会提示没有权限,推荐创建目录 /opt/pecl/

sudo mkdir /opt/pecl
cd /opt/pecl/
curl -o go-pear.php http://pear.php.net/go-pear.phar
sudo php go-pear.php

如果是低版本的php,可以下载

http://pear.php.net/go-pear

http://pear.php.net/go-pear.phar

安装过程同上

mac-os-x-install-pecl-01

Download PEAR

sudo mkdir /opt/pecl
cd /opt/pecl/
curl -O http://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.

  1. Type 1 and press return.
  2. Enter:

    /usr/local/pear
    
  3. Type 4 and press return.
  4. Enter:

    /usr/local/bin
    
  5. Press return

pecl 安装成功验证

$ which pecl
/usr/local/bin/pecl

 

 

Mac OS X 安装 pecl (/usr/lib/php/ 提示没有权限,此方法行不通)

cd /usr/lib/php
sudo php install-pear-nozlib.phar 

pecl 安装日志:

$ sudo php install-pear-nozlib.phar
Password:
[PEAR] Archive_Tar    - installed: 1.3.11
[PEAR] Console_Getopt - installed: 1.3.1
warning: pear/PEAR requires package "pear/Structures_Graph" (recommended version 1.0.4)
warning: pear/PEAR requires package "pear/XML_Util" (recommended version 1.2.1)
[PEAR] PEAR           - installed: 1.9.4
Wrote PEAR system config file at: /usr/local/etc/php/5.6/pear.conf
You may want to add: /usr/local/Cellar/php56/5.6.30_6/lib/php/pear to your php.ini include_path
[PEAR] Structures_Graph- installed: 1.0.4
[PEAR] XML_Util       - installed: 1.2.1

 

Mac 安装 pear

brew install homebrew/science/pear

$ which pear
/usr/local/bin/pear

 

编辑文件 php.ini

vim  /usr/local/etc/php/5.6/php.ini

将其中的include_path改为:

include_path = ".:/usr/local/Cellar/php56/5.6.30_6/lib/php/pear"

 

然后,执行命令:

sudo pear channel-update pear.php.net
sudo pecl channel-update pecl.php.net 
sudo pear upgrade-all

即可。

 

 

Redis、Memcache、Mongo等扩展安装

sudo pecl install redis
sudo pecl install memcache
sudo pecl install mongo
sudo pecl install xdebug

.so 文件目录为:

/usr/local/Cellar/php56/5.6.30_6/lib/php/extensions/no-debug-non-zts-20131226/

 

错误处理:

sudo pecl install mongo 

错误提示信息:

/private/tmp/pear/install/mongo/contrib/php-ssl.h:33:10: fatal error: 'openssl/evp.h' file not found
#include <openssl/evp.h>
         ^
1 error generated.

make: *** [io_stream.lo] Error 1
ERROR: `make' failed

原因是需要安装 openssl

brew install --force openssl
brew install --force openssl-devel

然后,openssl 建立软连接

ln -s /usr/local/Cellar/openssl/1.0.2k/include/openssl /usr/local/include/openssl

mongo 安装问题解决!

 

 

将扩展配置添加的php.ini文件中:

extension=memcache.so
extension=mongo.so
extension=redis.so
zend_extension=xdebug.so

 

安装 xcache

从官网下载,解压缩并安装

tar xvf xcache-3.2.0.tar
cd xcache-3.2.0
phpize
./configure
make
sudo make install

 

配置XCache

[xcache]
xcache.size = 128M
xcache.var_size = 8M
xcache.var_count = 1
xcache.var_slots = 8K
xcache.var_ttl = 0
xcache.var_maxttl = 0
xcache.var_gc_interval = 300
xcache.optimizer = Off

由于Mac自带的PHP环境是不包括mcrypt扩展的,所以需要下载同版本的php源码包,单独编译这个模块加载。从官网的归档里面找到php5.5.14的源码包,下载:http://php.net/releases/

tar zxvf php-5.5.14.tar.gz
cd php-5.5.14/ext/mcrypt/
phpize。/configure
make
sudo make install

 

配置 ext-mcrypt

extension=mcrypt.so

为了加速,还需要打开opcache。
zend_extension=opcache.so
[opcache]
; Determines if Zend OPCache is enabled
opcache.enable=0
; Determines if Zend OPCache is enabled for the CLI version of PHP
opcache.enable_cli=0