安装PHP Redis扩展
1、查看本机已经安装的Redis版本
brew info redis
redis: stable 5.0.7 (bottled), HEAD Persistent key-value database, with built-in net interface https://redis.io//usr/local/Cellar/redis/5.0.7 (13 files, 3.1MB) * Poured from bottle on 2020-02-19 at 11:12:25 From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/redis.rb==> Options --HEAD Install HEAD version ==> Caveats To have launchd start redis now and restart at login: brew services start redis Or, if you don't want/need a background service you can just run: redis-server /usr/local/etc/redis.conf ==> Analytics install: 33,849 (30 days), 107,922 (90 days), 479,551 (365 days) install-on-request: 32,460 (30 days), 102,655 (90 days), 450,102 (365 days) build-error: 0 (30 days)
由上面的安装信息可以看出Redis安装的版本为
redis: stable 5.0.7
2、进入PHP官网下载Redis扩展 http://pecl.php.net/package/redis 下载对应版本的扩展
3、解压下载下来的安装包
cp 压缩包文件到 /Users/zaneli/WorkSpace/redis
cd /Users/zaneli/WorkSpace/redis/
tar -xzvf redis-5.1.0.tgz
4、通过phpize生成编译configure配置文件
zaneli@bogon cd redis-5.1.0
sudo find / -name phpize
/usr/bin/phpize
/usr/local/Cellar/php@7.2/7.2.27/bin/phpize
sudo find / -name php-config
Password:
/usr/bin/php-config
/usr/local/Cellar/php@7.2/7.2.27/bin/php-config
sudo ./configure --with-php-config=/usr/local/Cellar/php@7.2/7.2.27/bin/php-config
sudo make
sudo make install
5、编辑 php.ini文件,在最后一行添加 extension="redis.so"
cd /usr/local/etc/php/7.2
zaneli@bogon 7.2 % ls conf.d pear.conf php-fpm.conf php-fpm.d php.ini zaneli@bogon 7.2 % vim php.ini
zaneli@bogon 7.2 % brew services restart php@7.2
Stoppingphp@7.2
... (might take a while) ==> Successfully stoppedphp@7.2
(label: homebrew.mxcl.php@7.2) ==> Successfully startedphp@7.2
(label: homebrew.mxcl.php@7.2)
zaneli@bogon 7.2 % brew services restart
nginx Stoppingnginx
... (might take a while) ==> Successfully stoppednginx
(label: homebrew.mxcl.nginx) ==> Successfully startednginx
(label: homebrew.mxcl.nginx)
zaneli@bogon 7.2 % pwd /usr/local/etc/php/7.2
6、测试Redis 安装配置情况
vim /Users/zaneli/WorkSpace/test/redis.php 保存
<?php
//实例化redis对象
$redis = new redis();
//连接redis,第一个参数是redis服务的IP127.0.0.1是自己的,6379是端口号
$redis->connect('127.0.0.1', 6379);
echo "Server is running: " . $redis->ping();