先安装 redis

brew install redis
# 启动服务
brew services start redis

查看 php 安装位置

sudo which php

/opt/homebrew/opt/[email protected]/bin/php

# 进入到php安装目录
cd /opt/homebrew/opt/[email protected]/bin/
# 克隆
git clone [<https://github.com/nicolasff/phpredis.git>](<https://github.com/nicolasff/phpredis.git>)
# 进入 phpredis 目录
cd phpredis
# 使用 `phpize` 命令编译生成 `configure` 配置文件
sudo /opt/homebrew/opt/[email protected]/bin/phpize
# sudo /usr/local/opt/[email protected]/bin/phpize
# 配置 `phpredis` 命令
./configure --with-php-config=/opt/homebrew/opt/[email protected]/bin/php-config
# ./configure --with-php-config=/usr/local/opt/[email protected]/bin/php-config
# 编译安装
make && make install
make test

会得到扩展路径

Installing shared extensions:

/opt/homebrew/Cellar/[email protected]/7.3.33_3/pecl/20180731/

Installing shared extensions: /usr/local/Cellar/[email protected]/7.3.33_7/pecl/20180731/

# 打开php7.3配置文件
sudo vim /opt/homebrew/etc/php/7.3/php.ini
# 修改扩展路径
extension_dir = "/opt/homebrew/Cellar/[email protected]/7.3.33_2/pecl/20180731/”
# 添加
extension=redis.so
# 重启php
brew services restart shivammathur/php/[email protected]
/usr/local/Cellar/[email protected]/7.4.33_6/pecl/20190902/