安装 phpredis MAC OSX

Install phpredis MAC OSX

谁能帮我安装 php-redis in MAC OSX .

brew install php-redis

不工作。

pecl install php-redis

也无法正常工作 -

invalid package name/package file "php-redis".

Homebrew Error:

homebrew_error

git clone https://www.github.com/phpredis/phpredis.git
cd phpredis
phpize && ./configure && make && sudo make install

在您的 php.ini

中添加 extension=redis.so
brew services restart php@7.2
make test

你可以检查工作与否

php -r "if (new Redis() == true){ echo \"\r\n OK \r\n\"; }"

截至 2019 年,使用自制程序 php7.2 及更高版本,pecl 现在默认与 php 二进制文件一起安装。

要亲自查看,请键入 which pecl

安装步骤

  1. 检查你的redis版本,然后找到合适版本的扩展here.

  2. 如果不熟悉 pecl,请键入 pecl 以查看选项。

  3. 问题pecl install redis-5.0.2。 (或您的版本)。如果您不确定,请对询问的每个问题输入否。

  4. 如果成功检查它在以下位置创建的新文件:/usr/local/lib/php/pecl/20180731/redis.so

  5. 安装会将 extension="redis.so" 添加到 php ini 的顶部。 通过打开文件 /usr/local/etc/php/7.3/php.ini 检查。 (假设您使用的是 7.3)

  6. brew services restart php.

  7. php -i | grep Redis

Redis Support => enabled
Redis Version => 5.0.2

这是我在 2019 年 9 月刚做的,对我有用。

如果上面写的不起作用(请先尝试his/her回答),

首先,尝试先卸载(如果有但坏了):

sudo pecl uninstall redis 

之后 运行:

sudo pecl install redis

之后,在 php.ini 中使用扩展的完整路径。

我的是 /usr/local/Cellar/php@7.3/7.3.21/pecl/20180731/redis。所以(假设您使用的是 php@7.3)

所以在我的 php.ini 文件的顶部是这样的:

extension="/usr/local/Cellar/php@7.3/7.3.21/pecl/20180731/redis.so"