centos redis 安裝 php-redis擴展安裝 及使用


前提:centos7、php7

安裝redis-server

1:yum install redis

編譯安裝php-redis 擴展

1:下載編譯安裝

wget https://codeload.github.com/phpredis/phpredis/zip/php7
//解壓
unzip php7
cd phpredis-php7
//通過phpize生成configure
/use/bin/phpize
編譯
./configure
make && make install

 

2:修改php.ini配置 加上redis擴展 

//vim php.ini 添加 extension=redis.so
extension=redis.so

 

3:phpinfo可查看該擴展已成功安裝

 

redis命令:

  redis-cli  鏈接redis

  ping    測試redis啟動成功

  flushdb  清空當前數據

  set mykey 'xxx' 添加數據 

  CONFIG GET requirepass  獲取密碼

  CONDIG SET requirepass password  設置密碼

  AUTH password  使用密碼認證 

 

啟動redis服務

redis-server /usr/local/etc/redis.conf

 關閉redis服務

無密碼:redis-cli shutdown
有密碼:redis-cli -a "password" shutdown

查看redis進程

MAC:lsof -i tcp:6379
CENTOS:ps -ef | grep redis

 第二次:編譯安裝php-reids擴展

 下載php-redis擴展 安裝;

#下載
git clone https://github.com/phpredis/phpredis
cd phpredis
#生成configure文件;找到你的php-config文件,並指過去;
phpize /configure --with-php-config=/usr/local/php/bin/php-config
#安裝
make && make install
#找到你的php.ini文件;添加下面;或者找到生成的redis.so寫絕對路徑;
extension=redis.so;
#重啟php-fpm即可
service php-fpm restart
servoce nginx restart

與第一次沒什么變化 就是第二次configure沒有指明php-config;默認沒有找到;所以configure 后面指明了php-confiure路徑;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM