您的位置:首页 > 数据库 > Redis

Linux下安装Redis并添加PHP扩展

2016-04-21 17:25 603 查看

1.安装Redis客户端

1.1下载redis客户端

进入redis官网,然后使用wget下载redis客户端

[root@localhost ~]# wget http........




下载之后的安装包!

1.2解压

[root@localhost ~]# tar -zxvf redis-3.0.7.tar.gz




1.3安装配置

进入到redis-3.0.7文件夹,执行make install

并执行./utils/install_server.sh配置Redis的开机启动

[root@localhost redis-3.0.7]# make install
[root@localhost redis-3.0.7]# ./utils/install_server.sh


1.4Redis的启动和关闭

//使用ps -ef | grep redis 来查看redis的启动情况
[root@localhost ~]# ps -ef | grep redis
//使用/etc/init.d/redis_6379 start来开启redis
[root@localhost ~]# /etc/init.d/redis_6379 start
//使用/etc/init.d/redis_6379 stop来关闭redis
[root@localhost ~]# /etc/init.d/redis_6379 stop


2.安装php的redis扩展

2.1下载phpredis

[root@localhost ~]# wget https://github.com/phpredis/phpredis/archive/2.2.4.tar.gz[/code] 


2.2解压文件

[root@localhost ~]# tar -zxvf 2.2.4.tar.gz




2.3编译并添加扩展



接下来执行:

[root@localhost phpredis-2.2.4]# ./configure --with-php-config=/usr/local/php/bin/php-config
[root@localhost phpredis-2.2.4]# make && make install


基本的设置已经完成了!大家可以进入php放扩展文件的目录,可以发现里面多了一个redis.so文件

最后一步就是向php.ini中添加redis扩展



[root@localhost ~]# cd /usr/local/php/etc


修改里面的php.ini文件,向其中添加extension=redis.so

[root@localhost ~]# vim /usr/local/php/etc/php.ini


3.测试

打开phpinfo。如果可以发现redis扩展就说明成功了!

创建php文件测试redis

testredis.php

<?php

$redis = new Redis();
$redis->connect('127.0.0.1', 6379);

echo "Connection to server successfully";
echo "Server is running:".$redis->ping();
?>


屏幕输出这样的信息表示成功!

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  php redis linux 扩展