在centos7中为php7安装redis扩展

下载redis

下载redis,解压,编译:


$ wget http://download.redis.io/releases/redis-4.0.6.tar.gz
$ tar xzf redis-4.0.6.tar.gz
$ cd redis-4.0.6
$ make && make PREFIX=/usr/local/redis install  #安装到指定目录
--------------------- 
作者:大明湖畔黑熊怪丶 
来源:CSDN 
原文:https://blog.csdn.net/xujialei0704/article/details/80362602 
版权声明:本文为博主原创文章,转载请附上博文链接!

现在去刚刚tar包解压出来的源码目录中,拷贝一个redis.conf配置文件,放到/usr/local/redis/bin/目录下


进入到redis目录下,运行vi redis.conf

将daemonize no改为 daemonize yes保存退出

通过下面的命令启动Redis服务:

./bin/redis-server ./redis.conf

你可以使用内置的客户端命令redis-cli进行使用:

$ ./redis-cli
redis> set foo bar
OK
redis> get foo
"bar"
以上呢是安装redis程序

在php7中要开启redis扩展

使用git clone下载git上的phpredis扩展包

[root@localhost local ]#git clone  https://github.com/phpredis/phpredis.git

到了这一步,我们要使用安装php时生成的phpize来生成configure配置文件,

//具体用哪个要取决于你的phpize文件所在的目录,这时你应该用 whereis phpize 来查看路径

[root@localhost local ]# whereis phpize
phpize: /usr/bin/phpize /usr/share/man/man1/phpize.1.gz

这里表明路径为/usr/bin/phpize,然后执行:

[root@localhost phpredis ]# /usr/bin/phpize
Can't find PHP headers in /usr/include/php
The php-devel package is required for use of this command.

这里报错了,原因是没有安装好php-devel,由于我是使用的php7.0所以执行以下命令:

[root@localhost phpredis]#yum -y install php70w-devel

然后再次执行:

[root@localhost phpredis]# /usr/bin/phpize
Configuring for:
PHP Api Version: 20151012
Zend Module Api No: 20151012
Zend Extension Api No: 320151012

执行完上一步,我们就有了 configure 配置文件了,接下来配置

[root@localhost phpredis]#./configure

或者执行

[root@localhost phpredis]#./configure --with-php-config=/usr/bin/php-config

接下来是编译安装

[root@localhost phpredis]#make 

[root@localhost phpredis]# make install

 Installing shared extensions:      /usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/
配置php的配置文件php.ini(具体放在那里可以用 whereis php.ini 来查看),我的配置文件php.ini在/etc/下

[root@localhost phpredis]#vim /etc/php.ini

开启redis扩展:

extension = redis.so

redis.so文件的路径可以在make install的时候看到

[root@localhost local]# php -m  #查询php的扩展

重启nginx服务器,重启php-fpm,使配置生效

重启之后我们打开info.php,已经可以看到redis的扩展信息了

三 配置redis

Redis的配置信息,主要通过修改redis.conf文件实现,通过vi打开redis.conf文件,主要对以下参数进行设置。

daemonize 如果需要在后台运行,把该项改为yes

bind 绑定ip,设置后只接受来自该ip的请求,设置为127.0.0.1或者0.0.0.0

Requriepass 设置 登陆时需要使用密码,可以通过#号注释掉,也就是不设置密码

linux下redis设置密码登录

redis设置密码访问

你的redis在真是环境中不可以谁想访问就可以访问,所以必须要设置密码

设置密码的流程如下:

vim  /etc/redis.conf

#requirepass foobared去掉注释,foobared改为自己的密码,我在这里改为

requirepass 123456

然后保存,重启服务

cd /usr/local/bin

./redis-server /etc/redis.conf

测试连接:./redis-cli 

输入命令 会提示(error) NOAUTH Authentication required. 这是属于正常现象。

我们输入 auth  123456#你刚才设置的密码

分类: redis

猜你喜欢

转载自blog.csdn.net/weixin_41647577/article/details/84315916
今日推荐