Redis非关系型数据库—LNMP平台对接redis服务
一、LNMP平台对接redis服务
1.1 安装LNMP各个组件
这边就不写安装步骤了,刷脚本即可
1.2 安装redis服务
前面装过,自行查看
1.3 安装redis扩展
官网:http://redis.io/
下载包:
https://codeload.github.com/phpredis/phpredis/zip/develop
http://download.redis.io/releases/redis-3.2.5.tar.gz
1.4 解压并编译安装
ar -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/
redis.so
1.5 修改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
1.6 测试连接
vim set.php
<?php
$redis = new redis();
$redis->connect('192.168.80.12', 6379);
$redis->set('gxd',"dashuaibi");
echo $redis->get('gxd);
?>
curl http://192.168.80.12/set.php
vim get.php
<?php
$redis = new redis();
$redis->connect('192.168.80.12', 6379);
$result = $redis->get('gxd');
var_dump($result);
?>
curl http://192.168.80.12/get.php