`
moqiang02
  • 浏览: 529001 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
文章分类
社区版块
存档分类
最新评论

CentOS6.5下安装Redis2.8.6和phpredis2.2.4扩展

 
阅读更多

一、版本说明


CentOS版本

[plain]view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. [root@localhost ~]# uname

  2. Linux

  3. [root@localhost ~]# uname -r

  4. 2.6.32-431.el6.i686

  5. [root@localhost ~]# uname -a

  6. Linux localhost 2.6.32-431.el6.i686 #1 SMP Fri Nov 22 00:26:36 UTC 2013 i686 i686 i386 GNU/Linux

  7. [root@localhost ~]# cat /etc/centos-release

  8. CentOS release 6.5 (Final)

Redis的版本


请到redis的官网下载最新的 http://redis.io/download

这里我们下载不是最新的稳定版的2.8.6,3.0.0因为是Beta版本所以不推荐生产环境使用,开发环境尝鲜还是可以的。



phpredis的版本

这里通过 redis官网的 http://redis.io/clients 找到PhpRedis 去github上就能找到啦 https://github.com/nicolasff/phpredis ,这里显示的版本是2.2.4 。



二、安装


1.安装redis

安装教程在redis的官网上就有,这里详细讲一下。

wget

下载网上的资源需要用到wget工具,有的同学的服务器可能是新装的还没有来得及装(比如我。。。)

[plain]view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. #安装wget

  2. yum install wget

ok,然后开始安装redis,顺便说一句,连接外国网站真是慢的不得了,两三次下载都卡住了 = =

[plain]view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. $ wget http://download.redis.io/releases/redis-2.8.6.tar.gz

  2. $ tar xzf redis-2.8.6.tar.gz

  3. $ cd redis-2.8.6

  4. $ make

make错误

然后。QAQ,make的时候又出现了错误

[plain]view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. make[3]: gcc:命令未找到

安装gcc

看来没有安装gcc....

[plain]view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. #安装gcc

  2. yum install gcc gcc-c++ kernel-devel

再次make错误

然后安装的时候又发现出现了错误

[plain]view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. zmalloc.h:50:31: 错误:jemalloc/jemalloc.h:没有那个文件或目录

  2. zmalloc.h:55:2: 错误:#error "Newer version of jemalloc required"

然后去百度了,解决方案为

[plain]view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. make MALLOC=libc

make完成

接下来就是耐心等待,下面是我看到的结果。

[plain]view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. Hint: To run 'make test' is a good idea ;)

  2. make[1]: Leaving directory `/root/redis-2.8.6/src'

这样就算安装完成了。


启动redis服务

请注意,如果你在make的时候出现上述的问题,那么,在启动redis服务的时候就要注意了

[plain]view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. #官方网站提示这样启动服务

  2. src/redis-server

  3. #但是出现了上面的问题后,请用下面的方式启动redis服务

  4. nohup src/redis-server redis.conf &

启动redis服务完成。


简单测试

下面是简单测试。

[plain]view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. [root@localhost redis-2.8.6]# src/redis-cli

  2. 127.0.0.1:6379> ping

  3. PONG

2.安装PhpRedis

phpize

phpredis属于php扩展,所以需要phpize,如果你的服务器没有安装phpize,要先安装

[plain]view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. #安装phpize

  2. yum install php-devel

下载源码包

直接用wget好了

[plain]view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. #wget下载github上的文件

  2. wget https://github.com/nicolasff/phpredis/archive/master.zip

unzip

下面要解压zip文件,首先,你,要,有个,unzip....

[plain]view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. #安装了这么多的软件,想想也该知道怎么装这个东西了吧

  2. yum install unzip

[plain]view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. #解压

  2. unzip master.zip

编译

下面正式开始编译php扩展

[plain]view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. #1.准备phpize编译环境

  2. [root@localhost phpredis-master]# phpize

  3. Configuring for:

  4. PHP Api Version: 20090626

  5. Zend Module Api No: 20090626

  6. Zend Extension Api No: 220090626

再次ls就会发现文件夹中多了几个配置文件

[plain]view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. #2.配置环境

  2. ./configure

这个步骤会将上一步准备好的配置文件进行执行

[plain]view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. #3.编译

  2. make && make install

balabala...........

[plain]view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. #编译完成

  2. Build complete.

  3. Don't forget to run 'make test'.

  4. Installing shared extensions: /usr/lib/php/modules/

进入/usr/lib/php/modules 文件夹,发现redis.so的扩展。


修改php.ini

[plain]view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. [root@localhost phpredis-master]# vi /etc/php.ini

添加下面的扩展

[plain]view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. extension=redis.so

重启服务器

[plain]view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. [root@localhost modules]# service httpd restart

  2. 停止 httpd: [确定]

  3. 正在启动 httpd: [确定]

查看phpinfo



三、总结

借用《七日七数据库》中的一句话,redis就像是无处不在的润滑油。

简单,快速。

我们从小到大,正是因为经历了足够多的事情才会成长。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics