天天看點

Linux上安裝Redis+PHP安裝Redis擴充1.下載下傳2.安裝redis3.配置4.php安裝redis擴充

1.下載下傳

下載下傳位址:wget http://download.redis.io/releases/redis-4.0.8.tar.gz

[[email protected]]#wget http://download.redis.io/releases/redis-4.0.8.tar.gz    (位址若失效請更換)

Linux上安裝Redis+PHP安裝Redis擴充1.下載下傳2.安裝redis3.配置4.php安裝redis擴充

解壓:[[email protected] redis]# tar xzf redis-4.0.8.tar.gz

Linux上安裝Redis+PHP安裝Redis擴充1.下載下傳2.安裝redis3.配置4.php安裝redis擴充

重命名

[[email protected] redis]# mv redis-4.0.8 redis

Linux上安裝Redis+PHP安裝Redis擴充1.下載下傳2.安裝redis3.配置4.php安裝redis擴充

進入目錄 cd redis

Linux上安裝Redis+PHP安裝Redis擴充1.下載下傳2.安裝redis3.配置4.php安裝redis擴充

2.安裝redis

安裝:使用make指令

[[email protected] redis]# sudo make && sudo make install

等待安裝完成。

3.配置

運作:[[email protected] redis]# src/redis-server   需要在redis的安裝目錄下執行指令。

Linux上安裝Redis+PHP安裝Redis擴充1.下載下傳2.安裝redis3.配置4.php安裝redis擴充

這個并不是在背景運作redis,是以當指令行界面關閉的時候,就會失去連結,是以為了友善,我們需要将他配置為背景運作

編輯配置檔案:vim redis.conf   redis.conf就在目前目錄下。将daemonize=no改為daemonize=yes  然後儲存。

Linux上安裝Redis+PHP安裝Redis擴充1.下載下傳2.安裝redis3.配置4.php安裝redis擴充

然後啟動

[[email protected] redis]# src/redis-server ./redis/conf

這個時候我們的redis服務段就已經背景運作了。

然後啟動用戶端:

src/redis-cli

Linux上安裝Redis+PHP安裝Redis擴充1.下載下傳2.安裝redis3.配置4.php安裝redis擴充

測試:set test  changyiyi     設定key  value

擷取: get  test

以上就是redis在linux上的簡單安裝配置。使用更多關于使用redis的文法,請參照redis官網:https://redis.io/

4.php安裝redis擴充

下載下傳phpredis擴充

下載下傳位址:https://github.com/nicolasff/phpredis/archive/2.2.4.tar.gz

執行指令:

[[email protected] local]# wget https://github.com/nicolasff/phpredis/archive/2.2.4.tar.gz

Linux上安裝Redis+PHP安裝Redis擴充1.下載下傳2.安裝redis3.配置4.php安裝redis擴充

解壓:tar zxvf

[[email protected] local]# tar zxvf 2.2.4.tar.gz

Linux上安裝Redis+PHP安裝Redis擴充1.下載下傳2.安裝redis3.配置4.php安裝redis擴充

執行phpize 

[[email protected] phpredis]# /usr/local/php5/bin/phpize   這個是根據自己實際的路徑進入

Linux上安裝Redis+PHP安裝Redis擴充1.下載下傳2.安裝redis3.配置4.php安裝redis擴充

指定php配置路徑:

[[email protected] phpredis]# ./configure --with-php-config=/usr/local/php5/bin/php-config

Linux上安裝Redis+PHP安裝Redis擴充1.下載下傳2.安裝redis3.配置4.php安裝redis擴充

編譯安裝:sudo make && sudo make install

執行指令:[[email protected] phpredis]# sudo make && make install

Linux上安裝Redis+PHP安裝Redis擴充1.下載下傳2.安裝redis3.配置4.php安裝redis擴充

将擴充加入php配置檔案php.ini中  php.ini的路徑是你自己環境的路徑

[[email protected] phpredis]# vim /etc/php/php.ini  

在裡面加入一行:/usr/local/php5/lib/php/extensions/no-debug-non-zts-20090626/redis.so

Linux上安裝Redis+PHP安裝Redis擴充1.下載下傳2.安裝redis3.配置4.php安裝redis擴充

然後儲存,重新開機php

ps -ef | grep php-fpm

Kill -quit 程序号

啟動php:

/usr/local/php5/sbin/php-fpm

然後在phpinfo()中檢視redis擴充:

Linux上安裝Redis+PHP安裝Redis擴充1.下載下傳2.安裝redis3.配置4.php安裝redis擴充

檢查php是否成功安裝php的redis擴充,并能夠使用。

建立一個測試php檔案redis.php

vim redis.php

鍵入内容:

<?php

$redis = new redis();
$redis->connect('127.0.0.1',6379);
$redis->set("test","Helloworld!");
$result = $redis->get("test");
 //檢測是否連接配接成功
echo "Server is running: " . $redis->ping();
echo "\n";
echo $result;
           

?>

Linux上安裝Redis+PHP安裝Redis擴充1.下載下傳2.安裝redis3.配置4.php安裝redis擴充

執行php檔案。

php redis.php

Linux上安裝Redis+PHP安裝Redis擴充1.下載下傳2.安裝redis3.配置4.php安裝redis擴充

輸出:Server is running: +PONG.....

成功!可以在php中開始愉快的使用redis了。