Home  >  Article  >  Backend Development  >  What should I do if php cannot connect to redis?

What should I do if php cannot connect to redis?

藏色散人
藏色散人Original
2021-09-02 09:41:273941browse

Solution to the problem that PHP cannot connect to redis: 1. Open the redis server through the "./src/redis-server configuration file --port port number &" command; 2. Use iptables to open the port.

What should I do if php cannot connect to redis?

The operating environment of this article: linux5.9.8 system, PHP7.1 version, Dell G3 computer

#What if php cannot connect to redis? manage? Some problems when php fails to connect to redis

1.redis extension

php error message appears Class 'Redis' not found, this situation is generally because the redis extension does not exist Turn on. Go to https://pecl.php.net/package/redis address to download the redis extension corresponding to PHP. After compiling on Linux, download the dll file on Windows. Please refer to Baidu to open it. This article mainly introduces the following two methods.

2.redis is protected (this situation only occurs between two hosts)

The following error occurs when connecting to redis:

DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients.

The solution given by the author here is to change the downlink

bind 127.0.0.1

to

 bind 127.0.0.1 192.168.0.199 (注:笔者测试服务器的内网ip是192.168.0.199)

and add the server’s intranet ip to the back, so that the solution can be solved. Of course, if the intranet is For inter-network communication, add the internal network IP, and for the external network, add the external network IP.

3.reids connect error

There are two possibilities when the php link fails.

1. The redis server is not turned on. The method to turn it on is as follows:

./src/redis-server configuration file --port port number&

& is the background run.

2. The port is not open to the outside world (this situation only occurs between two hosts). The solution is as follows:

Please open the corresponding port number and use iptables to open the port. Please see The author's historical article http://blog.sina.com.cn/s/blog_8ff955df0102x87u.html

Since it is redis, for the sake of security, the author here recommends using the method of opening the port for the specified IP to avoid anyone Both can connect to your redis server.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What should I do if php cannot connect to redis?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn