centos 安装php扩展redis

来源:互联网 发布:reflower for mac 编辑:程序博客网 时间:2024/06/08 17:15

1.安装redis

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

wget

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

[plain] view plain copy print?
  1. #安装wget  
  2. yum install wget  

ok,然后开始安装redis,顺便说一句,连接外国网站真是慢的不得了,两三次下载都卡住了 = =
[plain] view plain copy print?
  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的时候又出现了错误


安装gcc

看来没有安装gcc....

[plain] view plain copy print?
  1. #安装gcc  
  2. yum install gcc gcc-c++ kernel-devel  


再次make错误

然后安装的时候又发现出现了错误
[plain] view plain copy print?
  1. zmalloc.h:50:31: 错误:jemalloc/jemalloc.h:没有那个文件或目录  
  2. zmalloc.h:55:2: 错误:#error "Newer version of jemalloc required"  

然后去百度了,解决方案为
[plain] view plain copy print?
  1. make MALLOC=libc  


make完成

接下来就是耐心等待,下面是我看到的结果。
[plain] view plain copy print?
  1. Hint: To run 'make test' is a good idea ;)  
  2.   
  3. make[1]: Leaving directory `/root/redis-2.8.6/src'  

这样就算安装完成了。

启动redis服务

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

[plain] view plain copy print?
  1. #官方网站提示这样启动服务  
  2. src/redis-server  
  3. #但是出现了上面的问题后,请用下面的方式启动redis服务  
  4. nohup src/redis-server redis.conf &  

启动redis服务完成。

简单测试

下面是简单测试。

[plain] view plain copy print?
  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 plain copy print?
  1. #安装phpize  
  2. yum install php-devel  

下载源码包

直接用wget好了

[plain] view plain copy print?
  1. #wget下载github上的文件  
  2. wget https://github.com/nicolasff/phpredis/archive/master.zip  


unzip

下面要解压zip文件,首先,你,要,有个,unzip....
[plain] view plain copy print?
  1. #安装了这么多的软件,想想也该知道怎么装这个东西了吧  
  2. yum install unzip  

[plain] view plain copy print?
  1. #解压  
  2. unzip master.zip  


编译

下面正式开始编译php扩展
[plain] view plain copy print?
  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 plain copy print?
  1. #2.配置环境  
  2. ./configure  

这个步骤会将上一步准备好的配置文件进行执行
[plain] view plain copy print?
  1. #3.编译  
  2. make && make install  

balabala...........
[plain] view plain copy print?
  1. #编译完成  
  2. Build complete.  
  3. Don't forget to run 'make test'.  
  4.   
  5. Installing shared extensions:     /usr/lib/php/modules/  

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


修改php.ini

[plain] view plain copy print?
  1. [root@localhost phpredis-master]# vi /etc/php.ini  


添加下面的扩展
[plain] view plain copy print?
  1. extension=redis.so  

重启服务器

[plain] view plain copy print?
  1. [root@localhost modules]# service httpd restart  
  2. 停止 httpd:                                               [确定]  
  3. 正在启动 httpd:                                           [确定]  

查看phpinfo






原创粉丝点击