网站制作学习网Linux→正文:linux php安装redis
字体:

linux php安装redis

Linux 2015/3/21 15:55:59  点击:不统计


http://www.forasp.cn/
 在linux 中配置php连接redis步骤,

1首先下载redis 安装redis服务
http://download.redis.io/releases/redis-2.6.17.tar.gz
下载可以根据自己的版本,然后解压
>tar -xf redis-2.6.17.tar.gz
>cd redis-2.6.17 
>make
>make install
注意:在make过程中出现  You need tcl 8.5 or newer in order to run the Redis test 的错误
解决方案 点击这里 
启动redis 并输出对应的日志
>/usr/sbin/redis-server >/var/log/redis/redis.log &
 
2.然后按照phpredis的php扩展使php可以调用直接redis 找到 phpize
下载phpredis扩展
下载地址 https://github.com/owlient/phpredis/tarball/master 其他地方也有
下载文件名称:owlient-phpredis-2.1.1-1-g90ecd17.tar.gz
>tar -xf owlient-phpredis-2.1.1-1-g90ecd17.tar.gz
>cd owlient-phpredis-2.1.1-1-g90ecd17
>whereis phpize
>/usr/bin/phpize
Configuring for:
PHP Api Version:         20090626
Zend Module Api No:      20090626
Zend Extension Api No:   220090626
>whereis php-config
php-config: /usr/bin/php-config /usr/share/man/man1/php-config.1.gz
>./configure --with-php-config=/usr/bin/php-config
....
>make
...
>make install
Installing shared extensions:     /usr/lib64/php/modules/
 
完成扩展安装
 
3. 修改php.ini文件
在php.ini文件中新增加
extension=redis.so
重启php-fpm nginx(或者apache) 然后再用phpinfo()看php的扩展即可看到



 
 
4.测试 redis 
<?php
$redis = new Redis(); #实例化redis类
$redis->connect('127.0.0.1'); #连接服务器
$redis->set('itemkey', 'forasp '); #调用方法,设置string类型值
$redis->append('itemkey', '.cn'); #追加字符串
echo $redis->get('itemkey');  #获取redis key的值 
$redis->close(); #关闭连接
 
 
以上就是linux下php安装连接redis的方法了。

网站http://www.制forasp作.cn

·上一篇:You need tcl 8.5 or newer in order to run the Redis test >>    ·下一篇:linux查看磁盘格式 >>
推荐文章
最新文章