Mac OSX 安装phpredis最详细步骤

**

前言

**
Mac 默认的apache php环境下 安装 phpredis的详细步骤,基本上所有坑都趟过了 。。。

**

一、准备

**

如果没安装 autoconf, phpize 的时候会报错:

----------------------------------------------------------------------
    grep: /usr/include/php/main/php.h: No such file or directory
    grep: /usr/include/php/Zend/zend_modules.h: No such file or directory
    grep: /usr/include/php/Zend/zend_extensions.h: No such file or directory
    Configuring for:
    PHP Api Version:        
    Zend Module Api No:     
    Zend Extension Api No:  
    Cannot find autoconf. Please check your autoconf installation and the
    $PHP_AUTOCONF environment variable. Then, rerun this script.
----------------------------------------------------------------------

1.1、如果没安装homebrew,先安装homebrew,命令如下:

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

1.2、安装autoconf

  • 1.2.1、安装 autoconf
brew install autoconf
----------------------------------------------------------------------
Error: /usr/local/Cellar is not writable. You should change the
ownership and permissions of /usr/local/Cellar back to your
user account:
  sudo chown -R $(whoami) /usr/local/Cellar
----------------------------------------------------------------------

//用户及权限错误:(考虑到安全性,改完权限及用户以后还得改回来)

$ ls -l /usr/local
----------------------------------------------------------------------
drwxr-xr-x   5 root  wheel   170  8  5 17:10 Cellar
----------------------------------------------------------------------

// 解释 开头的 d 表示目录,跟权限无关,忽略,权限数值(读:4,写:2,执行:1);rwx:可读、可写、可执行、(2+1+4=7);r-x:可读、不可写、可执行(4+0+1=5);r-x:可读、不可写、可执行(4+0+1=5); 好了,默认的权限是755 改完777以后要改回755

  • 1.2.2、更改权限(把权限改成777)
$ sudo chmod -R 777 /usr/local/Cellar
  • 1.2.3、更改用户(可以输入 whoami 查看当前用户,用户改成 zhangwei )
$ sudo chown -R zhangwei /usr/local/Cellar
  • 1.2.4、 再次安装 autoconf
$ brew install autoconf
----------------------------------------------------------------------
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink .
/usr/local/opt is not writable.

You can try again using:
  brew link autoconf
----------------------------------------------------------------------

//好吧,/usr/local/opt 目录不可写,但是 autoconf已经安装完毕,只是没关联到brew。

  • 1.2.5、关联autoconf:
brew link autoconf
----------------------------------------------------------------------
Linking /usr/local/Cellar/autoconf/2.69... 19 symlinks created
----------------------------------------------------------------------

//关联成功,注意:这里不能用 sudo brew link autoconf 因为系统认为 sudo brew 是危险操作

1.3、下载并解压phpredis

下载文件:

wget -c https://nodeload.github.com/nicolasff/phpredis/zip/master

解压:
tar -zxvf master

//如果解压失败,可以用unzip解压

**

二、安装phpredis

**

2.1、phpize

进入安装后的master目录

cd master
$ sudo phpize
----------------------------------------------------------------------
grep: /usr/include/php/main/php.h: No such file or directory
grep: /usr/include/php/Zend/zend_modules.h: No such file or directory
grep: /usr/include/php/Zend/zend_extensions.h: No such file or directory
Configuring for:
PHP Api Version:        
Zend Module Api No:     
Zend Extension Api No: 
----------------------------------------------------------------------

//出现上面提示,说明 /usr/下没有include文件夹,需要先关联,对于OSX10.11 以上的系统,苹果设定了rootless机制,即使 sudo mkdir /usr/tmp 也会提示 “Permission denied” 没有权限,需要先关闭rootless

  • 2.1.1、先关闭 Rootless
    重启 Mac,听到开机启动声后按住 Command+R,进入恢复模式,在上面的菜单实用工具中找到并打开 Terminal 终端(如果顶部没出现菜单,请继续重启^_^)。输入如下命令:
$ csrutil disable

执行完命令后,重启电脑即可生效。为了系统的安全,建议大家平时都开启 Rootless($ csrutil enable),只有需要时才暂时关闭。

  • 2.1.2、先找到你电脑对应的OSX版本号对应的 .sdk
ls /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/
----------------------------------------------------------------------
//MacOSX.sdk    MacOSX10.12.sdk
----------------------------------------------------------------------

//后面那个 “MacOSX10.12.sdk” 就是Mac对应的版本号的sdk

  • 2.1.3、关联MacOSX10.12.sdk/usr/include目录到 usr/include
sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include /usr/include

2.2、配置 /configure

  • 2.2.1、查找 php-config 路径
$ sudo find / -name php-config
----------------------------------------------------------------------
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/bin/php-config
find: /dev/fd/phpredis-master: No such file or directory
find: /dev/fd/phpredis-master: No such file or directory
/usr/bin/php-config
----------------------------------------------------------------------

//最后一个 /usr/bin/php-config 是我们需要的路径

  • 2.2.2、配置 .configure
$ ./configure --with-php-config=/usr/bin/php-config

2.3、make && make install

  • 2.3.1、执行安装
sudo make && make install
----------------------------------------------------------------------

Build complete.
Don't forget to run 'make test'.

Installing shared extensions:     /usr/lib/php/extensions/no-debug-non-zts-20131226/
cp: /usr/lib/php/extensions/no-debug-non-zts-20131226/#INST@3913#: Permission denied
make: *** [install-modules] Error 1
----------------------------------------------------------------------

//又是用户权限问题

  • 2.3.2、改用户及权限
sudo chmod -R 777 /usr/lib/php/extensions/no-debug-non-zts-20131226
sudo chown -R zhangwei /usr/lib/php/extensions/no-debug-non-zts-20131226
  • 2.3.3、重新运行
sudo make && make install
----------------------------------------------------------------------

Build complete.
Don't forget to run 'make test'.

Installing shared extensions:     /usr/lib/php/extensions/no-debug-non-zts-20131226/
----------------------------------------------------------------------

//安装成功了
看一下

ls /usr/lib/php/extensions/no-debug-non-zts-20131226/
----------------------------------------------------------------------
redis.io
----------------------------------------------------------------------

//如果有 redis.so 扩展关联成功了

**

三、更改 php.ini

**

sudo find / -name php.ini
----------------------------------------------------------------------
/private/etc/php.ini
---------------------------------------------------------------------- 
sudo vi /private/etc/php.ini

按 / 并输入:redis
光标定位到

; extension=redis.so

把前面的 ; 去掉
按英文输入法的 : 输入wq ,(保存退出)

四、重启 apache

sudo apachectl restart

phpredis已经安装完成
验证 phpredis是否成功

php -m |grep redis
---------------------------------------------------------------------- 
redis
---------------------------------------------------------------------- 

//如果有 redis 说明已成功安装了phpredis

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值