linux(centOS7)安裝 redis及php操作redis____linux

來源:互聯網
上載者:User

Linux 安裝 Redis

1.安裝前的準備(安裝gcc)

yum install gcc-c++

2.將redis下載到/usr/local/src目錄下
cd /usr/local/srcwget http://download.redis.io/releases/redis-2.8.17.tar.gz  #下載tar xzf redis-2.8.17.tar.gz  #解壓cd redis-2.8.17  #進入安裝目錄make  #編譯

註:make完成後 redis-2.8.17目錄下會出現編譯後的redis服務程式redis-server,還有用於測試的用戶端程式redis-cli,兩個程式位於安裝目錄 src 目錄下

4.啟動redis服務

cd src./redis-server

註:./redis-server & 將redis服務運行在後台

注意上面啟動redis服務的方式使用的是預設配置。我們也可以通過啟動參數告訴redis使用指定設定檔,命令如下:

./redis-server redis.conf

redis.conf是預設的設定檔,我們可以根據需要使用自己的設定檔。

5.redis服務啟動後,我們就可以使用測試用戶端程式redis-cli和redis服務進行互動了。 

cd src./redis-cli127.0.0.1:6379>set key gentryOK127.0.0.1:6379> get key"gentry"

到此,Linux安裝Redis就告一段落。。。


接下來安裝php_redis.dll擴充讓php支援redis

1.安裝前的準備(安裝php-devel)

yum install php-devel

2.將擴充 用樣安裝到/usr/local/src目錄下

cd /usr/local/srcwget https://github.com/phpredis/phpredis/archive/2.2.4.tar.gz  #下載擴充tar zxf 2.2.4.tar.gzcd phpredis-2.2.4 /usr/bin/phpize  #phpize執行檔案的路徑
註:執行/usr/bin/phpize 前使用whereis phpize查看phpize的路徑

3.進行配置

./configure --with-php-config=/usr/bin/php-config
在進行上面的命令前,不妨同樣使用whereis php-config 查看php-config路徑

#編譯安裝make && make install
到這一步, php-redis 擴充就安裝完成啦。。。

php載入redis擴充

1.進入php.ini設定檔

vi /etc/php.ini在php.ini的任意行添加以下內容extension=redis.so
2.儲存退出,重啟apache

systemctl restart httpd
3.phpinfo查看redis是否安裝成功(看到下面的樣式,證明redis安裝成功啦)


4.進入/var/www/html 執行php代碼測試redis

$redis = new Redis();$redis->connect('192.168.1.249', 6379);$redis->set('key','gentry');echo $redis->get('key');
頁面能夠輸出gentry,一切都搞定啦。。。


如需要linux安裝memcache:http://blog.csdn.net/gentry__/article/details/51933874


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.