Ubuntu16.04 上 Redis 4.0 及php-redis擴充的安裝和使用

來源:互聯網
上載者:User
Ubuntu16.04 上 Redis 4.0 及php-redis擴充的安裝和使用 安裝Redis
    $ wget http://download.redis.io/release-4.0.1.tar.gz #從官網下載Redis 4.0.1    $ tar -zxvf redis-4.0.1.tar.gz #解壓到目前的目錄    $ cd redis-4.0.1 #進入解壓後的檔案夾    $ make #編譯    $ src/redis-server #啟動服務

到此安裝完成。 使用redis

本地使用Redis
進入解壓後的目錄裡邊的src目錄:

    $ cd redis-4.0.1/src    $ ./redis-cli

即可啟動redis用戶端,這裡不對Redis的使用作過多描述
遠程使用Redis
當你telnet Redis主機時,如果你未對Redis配置作任何修改,則會報:(error) DENIED Redis is running in protected mode is enabled……
這是因為Redis預設啟動保護模式,只能使用本地串連,如果要使用遠端連線,則需要對設定檔作如下修改:
首先開啟Redis設定檔,設定檔為解壓後目錄的redis.conf
1. 找到bind 127.0.0.1這一行,將其注釋掉,即#bind 127.0.0.1,

2. 找到protected-mode yes這一行,將yes改為no,即protected-mode no

3.找到#requirepass foobared這一行,將注釋去掉,將後面的參數改為自己想要的密碼,如requirepass 88888888然後啟動服務,這是一定要記住帶上參數, 在src目錄下,執行
$ ./redis-server ../redis.conf
我想第三步應該可以不用,但如果設定了密碼,在redis用戶端啟動後執行

auth 88888888,

在php上要使用

$redis = new Redis()`,$redis -> auth('88888888')

這裡還有一點要說明的是在php上使用時安裝php-redis擴充
參考:
http://www.cnblogs.com/redirect/p/6486356.html
http://blog.csdn.net/Up_Seeker/article/details/40709179
1. 下載php-redis
wget https://github.com/github.com/nicolasff/phpredis/zipball/master -O php-redis.zip

2. 解壓到目前的目錄
$ unzip php-redis.zip

3. 下一步很重要,看你的php什麼版本的,如果你是php 5.6版本的,那麼執行:
$ sudo apt-get install php5.6-dev
如果你是php 7.0版本的,那麼執行:
$ sudo apt-get install php7.0-dev
都有的話,就看你使用哪一個了,都不是的話,php5.6到php7.0的就裝5.6的,php7.0的就裝7.0的,不行的話,請自行Google(百度),這隻是我個人的看法。

4. 進入解壓縮後的目錄,執行:
$ phpize #這個是php-dev下的編譯擴充的工具

5. 回合組態檔案,產生makefile,這一步對應第三步的php版本,留意版本號碼:
$ sudo ./configure --with-php-config=/usr/bin/php-config5.6
如果php版本是7.0的話後面就改成php-config7.0

6. 執行make編譯檔案,產生共用庫(如redis.so)
$ sudo make

7. 安裝
$ sudo make install

8. 在/etc/php/5.6/mod-available下建立redis.ini,內容如下:

; configuration for php Redis module; priority=20extension=redis.so

9. 建立連結
$ sudo ln -s /etc/php/5.6/mod-available/redis.ini /etc/php5/apache2/conf.d/20-redis.ini

10. 重啟Apache
sudo service apache2 restart

11. 使用php裡邊的phpinfo()查看是否有Redis擴充

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.