**
**
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
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
$ sudo chmod -R 777 /usr/local/Cellar
$ sudo chown -R zhangwei /usr/local/Cellar
$ 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。
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解压
**
**
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
$ csrutil disable
执行完命令后,重启电脑即可生效。为了系统的安全,建议大家平时都开启 Rootless($ csrutil enable),只有需要时才暂时关闭。
ls /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/
----------------------------------------------------------------------
//MacOSX.sdk MacOSX10.12.sdk
----------------------------------------------------------------------
//后面那个 “MacOSX10.12.sdk” 就是Mac对应的版本号的sdk
sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include /usr/include
2.2、配置 /configure
$ 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 是我们需要的路径
$ ./configure --with-php-config=/usr/bin/php-config
2.3、make && make install
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
----------------------------------------------------------------------
//又是用户权限问题
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
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 扩展关联成功了
**
**
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