LNMP平台对接Redis服务

1、安装 LNMP 各个组件

 

 

 

 

2、安装 redis 服务

 

 

3、安装 redis 扩展

官网:http://redis.io/

下载包:
https://codeload.github.com/phpredis/phpredis/zip/develop
http://download.redis.io/releases/redis-3.2.5.tar.gz

tar -zxvf redis-4.0.2.tgz
cd /opt/redis-4.0.2

  

//运行 phpize 脚本的用途是动态安装 php 扩展模块

/usr/local/php/bin/phpize

  

 

 

//开始编译安装

./configure --with-php-config=/usr/local/php/bin/php-config --enable-redis
make && make install
//Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/
 
ls /usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/

  

 

4、修改 php 配置文件

vim /usr/local/php/lib/php.ini
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/"      #736行,指定redis模块目录
extension = "redis.so"                                                              #738行,修改参数项名称为extension,指定redis模块名称
 
 
systemctl restart php-fpm.service
php -m | grep redis

  

 

 

5、测试连接

cd /usr/local/nginx/html/
vim set.php
<?php
$redis = new redis();
$redis->connect('127.0.0.1', 6379);
$redis->set('test',"hello");
echo $redis->get('test');
?>
 
curl http://127.0.0.1/set.php
 
 
vim get.php
<?php
$redis = new redis();
$redis->connect('127.0.0.1', 6379);
$result = $redis->get('test');
var_dump($result);
?>
 
curl http://127.0.0.1/get.php
//结果:string(10) "hello"

  

 

 

 

 

 

 

 

posted @ 2021-09-24 00:21  视觉装置在笑  阅读(26)  评论(0编辑  收藏  举报