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
/* 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();*/
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)
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)
返回查看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());