windown Centos7安装redis和phpredis支持

centos7:

使用yum安装redis:

1>yum -y install redis

3>配置redis

    配置文件在/etc/redis.conf,修改以下内容

3.1.默认端口port为6379;
3.2.搜索绑定地址bind 127.0.01,注释此行用来接收全部IP请求,或者限制IP也可以。
3.3.搜索安全模式protected-mode yes,修改为protected-mode no
3.4.搜索默认密码requirepass foobared,修改为requirepass 123456

3.5.搜索daemonize字段,将no改为yes,将redis作为守护进程在后台运行

3.6.搜索appendonly字段,将no改为yes,用来持久化数据,在崩溃时候恢复

3.7.搜素dir和dbfilename字段,这两个是存放持久化文件的位置和名称。

4》对外服务

 4.1.查看iptables是否打开默认端口

 开启端口

  直接输入命令:iptables -A INPUT -p tcp --dport 6379 -j ACCEPT

  或者编辑:vim /etc/sysconfig/iptables

  最后一行添加:

  -A RH-Firewall-1-INPUT -m state NEW -m tcp -dport 8080 -j ACCEPT

   4.2.如果是云服务要在控制台中也打开此端口

5》systemctl

   systemctl list-unit-files 查看redis是否enable,如果没有使用systemctl enable redis.service开启。

     以后可以用systemctrl开启服务

6》安装php redis扩展模块

  如果是默认PHP版本

  yum -y install php-pecl-redis即可

  如果是5.6以上版本,不是默认库的,加上版本号即可:

  yum -y install php56w-pecl-redis即可

       验证

      命令认证:php -m | grep redis

           服务器认证:使用phpinfo()可以看到redis模块。

6.1》测试代码

<?php 
    //连接本地的 Redis 服务
   $redis = new Redis();
   $redis->connect('127.0.0.1', 6379);
   //$redis->auth('qwer@1234');
   echo "Connection to server sucessfully";
   //查看服务是否运行
   echo "Server is running: " . $redis->ping();
   $redis->delete('list1');
   $redis->lpush('list1',11);
   $redis->lpush('list1',12);
   $redis->lpush('list1',13);
   $val = $redis->lpop('list1');
   var_dump($val);
  
?>

6.2>windows下安装redis

  安装很多,百度搜索即可。主要记录php redis扩展安装:

  在phpinfo()中,

  php版本5.6,架构x86,ZendExt:TS,VC11

  php扩展需要2个文件,igbinary.dll和redis.dll

      redis.dll下载:

  https://windows.php.net/downloads/pecl/releases/redis/

     igbinary.dll下载

  https://windows.php.net/downloads/pecl/releases/igbinary/

  将2个dll文件放入\php\php5.5.12\ext中;

  然后,打开文件php.ini,在尾部添加上如下代码:

      ;redis

     extension=php_igbinary.dll
     extension=php_redis.dll
    重启服务器,查看phpinfo()即可。

 

posted @ 2019-05-16 16:36  糊糊饭团  阅读(118)  评论(0编辑  收藏  举报