LNMP平台对接redis
目录LNMP在连接数据库时,不是直接连接,而是由代码逻辑连接.承载这些代码的可能是php或者tomcat 等中间件去连接
官网:http://redis.io/
下载包:
https://codeload.github.com/phpredis/phpredis/zip/develop
http://download.redis.io/releases/redis-3.2.5.tar.gz
[root@host104 opt]# tar -xf redis-4.0.2.tgz [root@host104 opt]# cd /opt/redis-4.0.2/ #运行phpize 脚本的用途是动态安装php扩展模块 [root@host104 redis-4.0.2]# /usr/local/php/bin/phpize #开始编译安装 [root@host104 redis-4.0.2]# ./configure \ > --with-php-config=/usr/local/php/bin/php-config \ > --enable-redis [root@host104 redis-4.0.2]# make && make install #最后出现 Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/ [root@host104 redis-4.0.2]# ls /usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/
b[root@host104 redis-4.0.2]# vim /usr/local/php/lib/php.ini #736行,指定redis模块目录 736// extension_dir ="/usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/" #738行,修改参数项名称为extension,指定redis模块名称 738// extension = "redis.so" :wq systemctl restart php-fpm.service php -m | grep redis
cd /usr/local/nginx/html/ vim set.php <?php $redis = new redis(); $redis->connect('127.0.0.1', 6379); $redis->set('test',"1111111111"); echo $redis->get('test'); ?>
[root@host104 html]# 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