本章目录
1. 操作步骤
1. 操作步骤
(1)安装 LNMP 组件
详细步骤参考博客 Blog.049 LNMP 架构与源码编译安装
http://redis.io/
https://codeload.github.com/phpredis/phpredis/zip/develop
http://download.redis.io/releases/redis-3.2.5.tar.gz
1 tar -zxvf redis-4.0.2.tgz 2 cd /opt/redis-4.0.2 3 4 ##运行 phpize 脚本的用途是动态安装 php 扩展模块 5 /usr/local/php/bin/phpize 6 7 ##开始编译安装 8 ./configure --with-php-config=/usr/local/php/bin/php-config --enable-redis 9 make && make install 10 //Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/ 11 12 ls /usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/ 13 redis.so
(4)修改 php 配置文件
1 vim /usr/local/php/lib/php.ini 2 extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/" #736行,指定redis模块目录 3 extension = "redis.so" #738行,修改参数项名称为extension,指定redis模块名称 4 5 6 systemctl restart php-fpm.service 7 php -m | grep redis
(5)测试连接
1 cd /usr/local/nginx/html/ 2 vim set.php 3 <?php 4 $redis = new redis(); 5 $redis->connect('127.0.0.1', 6379); 6 $redis->set('test',"hello"); 7 echo $redis->get('test'); 8 ?> 9 10 curl http://127.0.0.1/set.php 11 12 13 vim get.php 14 <?php 15 $redis = new redis(); 16 $redis->connect('127.0.0.1', 6379); 17 $result = $redis->get('test'); 18 var_dump($result); 19 ?> 20 21 curl http://127.0.0.1/get.php 22 //结果:string(10) "hello"
-