您当前的位置:首页 > 分类 > 技术资讯 > LINUX > 正文

安装redis和phpredis模块

发布时间:2013-07-18 22:53:23      来源:51推一把
【摘要】redis的下载及安装:@ubuntu:/$ mkdir /usr/local/redis@ubuntu:/$ cd /usr/local/redis@ubuntu:/$ wget http://redis.googlecode.com/files/redis-2.4.2.tar.gz@ubuntu:/$ tar xzf redis-2.4.2.tar.gz@ubuntu:/$ cd redis-2.4.2@ubuntu:/$ make@ubuntu:/$ src/redis-se

redis的下载及安装:

@ubuntu:/$ mkdir /usr/local/redis

@ubuntu:/$ cd /usr/local/redis

@ubuntu:/$ wget http://redis.googlecode.com/files/redis-2.4.2.tar.gz

@ubuntu:/$ tar xzf redis-2.4.2.tar.gz

@ubuntu:/$ cd redis-2.4.2

@ubuntu:/$ make

@ubuntu:/$ src/redis-server


redis测试命令:

@ubuntu:/$ src/redis-cli

@ubuntu:/$ redis> set foo bar

@ubuntu:/$ OK

@ubuntu:/$ redis> get foo

@ubuntu:/$ "bar";

 

装了redis的服务器端程序,现在要在项目中使用REDIS了,由于我们的后台是用PHP来写的,所以要用redis的PHP客户端来使用它。PHP的客户端有几种:

 

Predis ★

Repository

JoL1hAHN

Mature and supported

 

phpredis ★

Repository

yowgi

This is a client written in C as a PHP module.

 

Rediska

Repository Homepage

shumkov

 

 

Redisent

Repository

justinpoliey

 

 

iRedis

Repository


dhorrigan
 

在这里我选择phpredis( C开发的扩展包 )这个PHP扩展。

@ubuntu:/$ wget https://download.github.com/owlient-phpredis-2.1.1-1-g90ecd17.tar.gz
@ubuntu:/$ tar zxvf owlient-phpredis-2.1.1-1-g90ecd17.tar.gz
@ubuntu:/$ cd owlient-phpredis-90ecd17/
@ubuntu:/$ /usr/local/php/bin/phpize
@ubuntu:/$ ./configure --with-php-config=/usr/local/php/bin/php-config
@ubuntu:/$ make
@ubuntu:/$ make install


注:用C开发PHP扩展的时候如果用动态链接库的方式编译扩展模块,需要用到phpize,这个工具在使用apt-get install php5默认情况也是没安装的,安装phpize:apt-get install php5-dev。 

 

修改配置文件:

修改php.ini文件  

在php.ini中添加如下一行:

extension=redis.so

重启nginx后生效。

 

最后开启redis服务:redis-server 或者 redis-server /etc/redis.conf(后台运行),

如果不开服务可能会出现 ”Uncaught exception RedisException with message Redis server went away?“错误