CentOS7yum安装redis及php扩展


安装redis

检查是否有redis yum源

yum list | grep redis

下载fedora的epel仓库

如果仓库存在,该步骤可忽略

yum install epel-release

安装redis数据库

yum install redis

启动或停止服务

设置开机启动

chkconfig redis on
#centos7
systemctl enable redis

启动命令:

service redis start
#centos7
systemctl start redis

停止命令:

service redis stop
#centos7
systemctl stop redis

查看运行状态:

service redis status
#centos7
systemctl status redis

重启命令:

systemctl restart redis

查看redis进程:

ps -ef | grep redis

防火墙配置

没有防火墙,此步骤可忽略

# 开启6379
/sbin/iptables -I INPUT -p tcp --dport 6379 -j ACCEPT
# 保存
/etc/rc.d/init.d/iptables save
# centos 7下执行
service iptables save

综合设置

  • 打开配置文件:vi /etc/redis.conf
  • 修改默认密码:查找 requirepass, 默认密码为 foobared, 将 foobared 修改为你的密码即可
  • 找到 bind 127.0.0.1 将其注释,否则redis只允许本机连接
  • 找到 protected-mode yes 将其改为:protected-mode no
  • daemonize yes 将redis-service设置为后台服务
  • 重启Redis:systemctl restart redis

安装php的redis扩展

添加RPM包的源

  • epel源
    #RHEL/CentOS6
    yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
    #RHEL/CentOS7
    yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
    
  • remi源
    # RHEL/CentOS6
    yum install https://rpms.remirepo.net/enterprise/remi-release-6.rpm
    # RHEL/CentOS7
    yum install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
    

查看可安装的PHP Redis扩展版本

yum list | grep redis

安装扩展

yum install php73-php-pecl-redis(扩展名称)

查看PHP已安装的扩展模块

php -m

windows设置redis为服务

redis-server.exe --service-install redis.windows.conf --loglevel verbose

window环境php-redis扩展地址:

https://windows.php.net/downloads/pecl/releases/igbinary/
把php_igbinary.dll和php_igbinary.pdb放ext下 https://windows.php.net/downloads/pecl/releases/redis/
把php_redis.dll和php_redis.pdb放ext下 在php安装目录下的php.ini 和apache安装目录下的php.ini 添加配置

Last Updated:
Contributors: hqdxhyf, huangyanfu