Centos下给php安装Redis扩展及编译问题解决

1、第一步自然是去github下载源码了,记得加上参数 --no-check-certificate,不然https校验会出错

wget https://github.com/phpredis/phpredis/archive/develop.zip --no-check-certificate

2、解压下载好的包,

unzip develop
cd phpredis-develop/

3、配置和编译,注意修改为php的安装目录位置

~/php/bin/phpize 
./configure --with-php-config=~/php/bin/php-config 
make && make install

正常情况下应该就编辑好so文件,并放到php的扩展目录下了,但是我在编译时出错了:

.libs/redis_cluster.o:(.data.rel.local+0x0): multiple definition of `arginfo_kscan'
.libs/redis.o:(.data.rel.local+0xa0): first defined here
.libs/redis_cluster.o:(.data.rel.local+0xe0): multiple definition of `arginfo_scan'
.libs/redis.o:(.data.rel.local+0x0): first defined here

看错误是集群的代码问题,反正我的环境用不上集群,就注释掉这段代码吧:
vim redis_cluster.c
找到41行,注释这2段代码:
/* Argument info for HSCAN, SSCAN, HSCAN */
/*ZEND_BEGIN_ARG_INFO_EX(arginfo_kscan, 0, 0, 2)
    ZEND_ARG_INFO(0, str_key)
    ZEND_ARG_INFO(1, i_iterator)
    ZEND_ARG_INFO(0, str_pattern)
    ZEND_ARG_INFO(0, i_count)
ZEND_END_ARG_INFO();*/

/* Argument infor for SCAN */
/*ZEND_BEGIN_ARG_INFO_EX(arginfo_scan, 0, 0, 2)
    ZEND_ARG_INFO(1, i_iterator)
    ZEND_ARG_INFO(0, str_node)
    ZEND_ARG_INFO(0, str_pattern)
    ZEND_ARG_INFO(0, i_count)
ZEND_END_ARG_INFO();*/

保存后继续make && make install,这回是调用出错了:
phpredis-develop/redis_cluster.c:177: error: 'arginfo_scan' undeclared here (not in a function)
phpredis-develop/redis_cluster.c:178: error: 'arginfo_kscan' undeclared here (not in a function)

继续编辑文件,删除下面4行调用代码:
PHP_ME(RedisCluster, evalsha, NULL, ZEND_ACC_PUBLIC)
//PHP_ME(RedisCluster, scan, arginfo_scan, ZEND_ACC_PUBLIC)
//PHP_ME(RedisCluster, sscan, arginfo_kscan, ZEND_ACC_PUBLIC)
//PHP_ME(RedisCluster, zscan, arginfo_kscan, ZEND_ACC_PUBLIC)
//PHP_ME(RedisCluster, hscan, arginfo_kscan, ZEND_ACC_PUBLIC)

ok,保存退出后再make && make install,这回成功了,

返回查看php/ext目录,有redis.so扩展了,重启php-fpm再看看phpinfo(),就有redis信息了:

Redis Support	enabled
Redis Version	2.2.5

写一段代码测试下吧:
$redis = new Redis();
$conn = $redis->connect('127.0.0.1',6379);
var_dump($redis->info());

页面应该会显示出redis的信息


猜你喜欢

转载自blog.csdn.net/youbl/article/details/50109105