您现在的位置是:首页 > 经验记录>Laravel日记>ubuntu 下搭建redis和php的redis的拓展 网站首页 Laravel日记

ubuntu 下搭建redis和php的redis的拓展

系统环境:

腾讯云服务器, ubuntu16.0.4.4 ,php7.0

 

一.安装redis服务

sudo apt-get install redis-server

安装好的redis目录在 /etc/redis [也可使用命令whereis redis 查找]

启动:

sudo service redis-server start

 

然后运行客户端命令redis-cli能够出现命令提示符127.0.0.1:6379: >就算成功了!

 

二.安装redis 拓展

1.安装redis和php的redis扩展

  

apt-get install git php-dev   //包含了phpize

  

git clone https://github.com/nicolasff/phpredis.git //克隆phpredis拓展
cd phpredis/
 phpize //生成PECL扩展的configure文件
 ./configure
 make //编译
 make install //安装

 

2.配置php的redis扩展

sudo vim /etc/php/7.0/fpm/php.ini 中写入 extension=redis.so

 

3.重启fpm,访问info.php,就能看到redis扩展

1
/etc/init.d/php7.0-fpm restart

 

4.读取测试

1
2
3
4
5
6
7
8
9
<?php
 
     $redis new Redis();
    //连接redis服务器
    $redis->connect('127.0.0.1''6379')or die ("Could net connect redis server!");;
    echo "Connection to server sucessfully 
"
;
 
    //查看服务是否运行
    echo "Server is running: " $redis->ping();

  参考链接:https://blog.csdn.net/setoy/article/details/77679976

                        https://blog.csdn.net/caoyouming0609/article/details/78197462

       原文地址:https://www.cnblogs.com/xiaotaoing/p/8718278.html



文章评论

未开放
Top