centos7安装PHP redis扩展
安装PHP redis扩展开始在 PHP 中使用 Redis 前,我们需要确保已经安装了redis服务,且你的机器上能正常使用PHP。 接下来让我们安装 PHP redis 驱动,下载地址为:https://github.com/phpredis/phpredis/releases。下载并安装最新版:$ wget https://github.com/phpredis/phpre...
·
安装PHP redis扩展
开始在 PHP 中使用 Redis 前,我们需要确保已经安装了redis服务,且你的机器上能正常使用PHP。 接下来让我们安装 PHP redis 驱动,下载地址为:https://github.com/phpredis/phpredis/releases。
下载并安装最新版:
$ wget https://github.com/phpredis/phpredis/archive/4.0.2.tar.gz
$ tar -zxvf phpredis-4.0.2.tar.gz
$ cd phpredis-4.0.2
$ /usr/local/php/bin/phpize # php安装后的路径
$ ./configure --with-php-config=/usr/local/php/bin/php-config
$ make && make install
将redis.so添加到php.ini中
$ echo 'extension=redis.so' >> /usr/local/php/etc/php.ini
重启php-fpm服务
$ /etc/init.d/php-fpm restart
查看redis扩展是否安装成功
$ php -m | grep redis
redis
测试:
<?php
//连接本地的 Redis 服务
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$redis->auth('123456');
echo "Connection to server sucessfully";
//查看服务是否运行
echo "Server is running: " . $redis->ping();
当前,我系统安装的PHP版本是7.2,实验证明PHP7.2已经支持Redis了。
如果执行phpize时报错: Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable. Then, rerun this script.
解决方法:
安装依赖 autoconf
$ yum -y install autoconf
更多推荐
已为社区贡献3条内容
所有评论(0)