xiang8 发表于 2015-7-21 07:17:57

安装redis和phpredis模块

  

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 ★RepositoryJoL1hAHNMature and supportedphpredis ★RepositoryyowgiThis is a client written in C as a PHP module.RediskaRepository Homepageshumkov RedisentRepositoryjustinpoliey iRedisRepository  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'?“错误
页: [1]
查看完整版本: 安装redis和phpredis模块