Get the App
SLTechnology News&Howtos  ›  Development  › 

How to solve the problem that php can't connect to redis?

Shulou Source: shulou.com Published: 2022-06-03 19:49:47 09月28日 Update

This article introduces the relevant knowledge of "how to solve the problem that php cannot be connected to redis". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Php can not connect to the redis solution: 1, through the ". / src/redis-server configuration file-port port number &" command to open the redis server; 2, use iptables to open the port.

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

What if php can't connect to redis? Some problems with the failure of php to connect to redis

1.redis extension

Class' Redis' not found appears when php reports an error, which is usually due to the fact that the redis extension is not enabled. Go to the https://pecl.php.net/package/redis address to download the redis extension corresponding to php. After linux compilation, windows downloads the dll file. The opening method is Baidu. This article mainly introduces the following two methods.

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

The following error occurred 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 go down

Bind 127.0.0.1

Change to

Bind 127.0.0.1 192.168.0.199 (Note: the intranet ip of the test server is 192.168.0.199)

Add the private network ip of the server to the back, which can be solved. Of course, if the communication between the internal networks adds the internal network ip, the external network adds the external network ip.

3.reids connect error

When a php link fails, there are two possibilities.

1. The redis server is not enabled, and the opening method is as follows:

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

& is running in the background.

two。 The port is not open to the public (this only occurs between two hosts). The solution is as follows:

Please open the corresponding port number and open the port using iptables.

Since it is redis, for the sake of security, I recommend using the method of opening the port for the specified ip to avoid that anyone can connect to your redis server.

This is the end of the content of "how to solve the problem that php can not connect to redis". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Method service situation port two between slogan file server author open host content more knowledge configuration utility security learning next Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft MariaDB Huawei Linux Shulou Tech Info