Linux安装Redis和php的redis扩展

一、安装Redis(各版本下载地址 http://download.redis.io/releases/)

wget -P /soft http://download.redis.io/releases/redis-stable.tar.gz  

cd /soft

tar xzf redis-stable.tar.gz

cd redis-stable/

把redis安装到指定目录

make PREFIX=/usr/local/redis install

把配置文件拷贝到指定目录

cp redis.conf /usr/local/bin/redis 

编辑配置文件

vim /usr/local/redis/bin/redis.conf  

把 daemonize no 改成 daemonize yes ,这样redis就在后台启动


启动redis

/usr/local/redis/bin/redis-server  /usr/local/redis/bin/redis.conf

测试

[root@VM_129_241_centos src]# /usr/local/redis/bin/redis-cli get name
(nil)
[root@VM_129_241_centos src]# /usr/local/redis/bin/redis-cli set name landy
OK
[root@VM_129_241_centos src]# /usr/local/redis/bin/redis-cli get name
"landy"

二、安装php的Redis扩展(安装包下载地址http://pecl.php.net/package/redis)

wget -P /soft http://pecl.php.net/get/redis-3.1.3.tgz

cd /soft

tar zxvf redis-3.1.3.tgz

cd redis-3.1.3

/usr/local/php/bin/phpize

./configure --with-php-config=/usr/local/php/bin/php-config

make

make install

成功安装后,在文件夹中会生成扩展

/usr/local/php/lib/php/extensions/no-debug-zts-20160303/ redis.so

配置php.ini文件

extension=redis.so
配置完要重启apache服务器
 /usr/local/apache2/bin/apachectl stop
/usr/local/apache2/bin/apachectl start

成功安装


三、php使用Redis

<?php
   //连接本地的 Redis 服务
   $redis = new Redis();
   $redis->connect('127.0.0.1', 6379);
   echo "Connection to server sucessfully";
   //设置 redis 字符串数据
   $redis->set("tutorial-name", "Redis tutorial");
   // 获取存储的数据并输出
   echo "Stored string in redis:: " . $redis->get("tutorial-name");



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值