4.2、安装php_redis扩展模块
[root@LNMP ~]# unzip phpredis-master.zip
[root@LNMP ~]# cd phpredis-master
[root@LNMP phpredis-master]# /usr/local/php5.5.30/bin/phpize
[root@LNMP phpredis-master]# ./configure --with-php-config=/usr/local/php5.5.30/bin/php-config
[root@LNMP phpredis-master]# make && make install
[root@LNMP phpredis-master]# ll /usr/local/php5.5.30/lib/php/extensions/no-debug-non-zts-20121212/
total 1668
-rwxr-xr-x. 1 root root 465457 Nov 2 06:21 memcache.so
-rwxr-xr-x. 1 root root 303946 Oct 14 04:24 opcache.a
-rwxr-xr-x. 1 root root 210011 Oct 14 04:24 opcache.so
-rwxr-xr-x. 1 root root 717996 Nov 2 18:35 redis.so
#说明php_redis模块已经安装成功
4.3、在php.php文件中配置php_redis模块
12345 [root@LNMP phpredis-master]# vim /usr/local/php5.5.30/lib/php.ini
extension_dir="/usr/local/php5.5.30/lib/php/extensions/no-debug-non-zts-20121212/"
extension="memcache.so"
extension="redis.so"
#如果以前配置过php扩展模块现在只需要加上这行即可。
4.4、查看php是否启动,如果启动则重启,如若没有启动则直接启动。
[root@LNMP phpredis-master]# netstat -tulnp | egrep "php|nginx"
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 9922/nginx
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 13361/php-fpm
[root@LNMP phpredis-master]# pkill php
[root@LNMP phpredis-master]# netstat -tulnp | egrep "php|nginx"
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 9922/nginx
[root@LNMP phpredis-master]# /usr/local/php5.5.30/sbin/php-fpm -t
[02-Nov-2015 18:53:33] NOTICE: configuration file /usr/local/php5.5.30/etc/php-fpm.conf test is successful
[root@LNMP phpredis-master]# /usr/local/php5.5.30/sbin/php-fpm -c /usr/local/php5.5.30/lib/php.ini
[root@LNMP phpredis-master]# netstat -tulnp | egrep "php|nginx"
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 9922/nginx
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 13400/php-fpm
4.5、在浏览器查看php_redis模块是否成功加载,本机是用linux命令行工具查看
[root@LNMP phpredis-master]# curl localhost/phpinfo.php|grep redis
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0<h2><a>redis</a></h2>
<tr><td>Registered save handlers </td><td>files user memcache redis </td></tr>
100 67295 0 67295 0 0 4433k 0 --:--:-- --:--:-- --:--:-- 6571k
This program is free software; you can redistribute it and/or modify it under the terms of the PHP License as published by the PHP Group and included in the distribution in the file: LICENSE
5、编写php程序测试php_redis模块
5.1、php连接redis的程序代码
<?php
$redis = new Redis();
$redis->connect('192.168.1.2',6379) or die("Could not connect redis");
$redis->set('mykey1','liangge');
echo "after insert get mykey1: ".$redis->get('mykey1');
$redis->delete('mykey1');
echo "<br>after delete get mykey1: ".$redis->get('mykey1');
?>
5.2、调试输出结果
after insert get mykey1: liangge
after delete get mykey1:
下面关于Redis的文章您也可能喜欢,不妨参考下: