centos下安裝redis 以及 phpredis擴展

CentOS版本


  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版本所以不推薦生產環境使用,開發環境嚐鮮還是可以的。

13940404576451.jpg


phpredis的版本

這裏通過 redis官網的 http://redis.io/clients 找到PhpRedis 去github上就能找到啦 https://github.com/nicolasff/phpredis ,這裏顯示的版本是2.2.4 。

13940404679464.jpg


二、安裝

1.安裝redis

安裝教程在redis的官網上就有,這裏詳細講一下。

wget

下載網上的資源需要用到wget工具

  1. #安裝wget  

  2. yum install wget  


ok,然後開始安裝redis,順便說一句,連接外國網站真是慢的不得了,兩三次下載都卡住了 = =



  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的時候又出現了錯誤


  1. make[3]: gcc:命令未找到  



安裝gcc


看來沒有安裝gcc....


  1. #安裝gcc  

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



再次make錯誤

然後安裝的時候又發現出現了錯誤


  1. zmalloc.h:50:31: 錯誤:jemalloc/jemalloc.h:沒有那個文件或目錄  

  2. zmalloc.h:55:2: 錯誤:#error "Newer version of jemalloc required"  


然後去百度了,解決方案爲



  1. make MALLOC=libc  



make完成

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


  1. Hint: To run 'make test' is a good idea ;)  

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


這樣就算安裝完成了。


啓動redis服務

請注意,如果你在make的時候出現上述的問題,那麼,在啓動redis服務的時候就要注意了


  1. #官方網站提示這樣啓動服務  

  2. src/redis-server  

  3. #但是出現了上面的問題後,請用下面的方式啓動redis服務  

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


啓動redis服務完成。


簡單測試

下面是簡單測試。


  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,要先安裝


  1. #安裝phpize  

  2. yum install php-devel  



下載源碼包


直接用wget好了


  1. #wget下載github上的文件  

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



unzip

下面要解壓zip文件,首先,你,要,有個,unzip....


  1. #安裝了這麼多的軟件,想想也該知道怎麼裝這個東西了吧  

  2. yum install unzip  


  1. #解壓  

  2. unzip master.zip  



編譯

下面正式開始編譯php擴展


  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就會發現文件夾中多了幾個配置文件


  1. #2.配置環境  

  2. ./configure  


這個步驟會將上一步準備好的配置文件進行執行



  1. #3.編譯  

  2. make && make install  


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



  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


  1. [root@localhost phpredis-master]# vi /etc/php.ini  



添加下面的擴展


  1. extension=redis.so  


或者直接

echo extension=redis.so > /etc/php.d/redis.ini


重啓服務器



  1. [root@localhost modules]# service httpd restart  

  2. 停止 httpd:                                               [確定]  

  3. 正在啓動 httpd:                                           [確定]  



查看phpinfo


13940404807902.jpg


三、總結

借用《七日七數據庫》中的一句話,redis就像是無處不在的潤滑油。

簡單,快速。

我們從小到大,正是因爲經歷了足夠多的事情纔會成長。


原文地址:http://www.centoscn.com/image-text/config/2014/0306/2504.html 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章