php7安装使用redis笔记

版权声明:转载请注明出处,谢谢! https://blog.csdn.net/dreamstone_xiaoqw/article/details/88263344

服务器已安装php7和redis

yum install redis

需要在代码中使用redis。

$redis = new Redis();
$redis->connect('127.0.0.1', 6379);

报错1 Redis.php): failed to open stream

扩展包需要源码编译的方式安装。

查阅得知,php需要安装redis扩展包,笔记如下:

 1053  2019-03-06 08:35:16 yum install git
 1054  2019-03-06 08:35:26 git clone https://github.com/phpredis/phpredis.git
 1055  2019-03-06 08:35:38 cd phpredis/
 1057  2019-03-06 08:35:44 phpize
 1063  2019-03-06 08:46:20 ./configure --with-php-config=/usr/local/php/bin/php-config

报错2 configure: error: Cannot find php-config. Please use --with-php-config=PATH

安装php7对应版本的php-config,再次config。注意PATH替换为php-config的路径

 1069  2019-03-06 08:47:20 ./configure --with-php-config=/usr/local/php/bin/php-config
 1071  2019-03-06 08:48:09 yum install php71w-config
 1103  2019-03-06 09:03:53 whereis php-config
 1104  2019-03-06 09:04:03 ./configure --with-php-config=/usr/local/php/bin/php-config --with-php-config=/usr/bin/php-config

报错3 make: *** [redis.lo] Error 1

有一条命令输错了…… 是PATH是查询which php-config而不是which php

 1104  2019-03-06 09:04:03 ./configure --with-php-config=/usr/local/php/bin/php-config --with-php-config=/usr/bin/php-config

成功

 1110  2019-03-06 09:04:26 make
 1111  2019-03-06 09:04:46 make test

Build complete

代码中使用

use Redis;

$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$redis->lpush("key", $value);
$value_list = $redis->lrange("key", 0, 5);

参考:
报错2 configure: error: Cannot find php-config
centos7 安装redis 开机启动

猜你喜欢

转载自blog.csdn.net/dreamstone_xiaoqw/article/details/88263344