了解在centos7中为php7安装redis扩展

发布时间:2022-05-24 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了了解在centos7中为php7安装redis扩展脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

了解在centos7中为php7安装redis扩展

推荐(免费):PHP7

下载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  #安装到指定目录

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

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

将daemonize no改为 daemonize yes保存退出

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

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

了解在centos7中为php7安装redis扩展

你可以使用内置的客户端命令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的扩展

了解在centos7中为php7安装redis扩展


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

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

了解在centos7中为php7安装redis扩展


更多相关学习推荐:PHP7教程

以上就是了解在centos7中为php7安装redis扩展的详细内容,更多请关注脚本宝典其它相关文章

脚本宝典总结

以上是脚本宝典为你收集整理的了解在centos7中为php7安装redis扩展全部内容,希望文章能够帮你解决了解在centos7中为php7安装redis扩展所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。