Home > Article > Backend Development > Solving the problem that PHP cannot open other sockets (permission denied) under apache
Today I plan to practice redis operation. When I run it on the command line, I find that the connection is smooth.
Later, I ran it with apache and found that it could not connect to the redis client (redis server went away).
By capturing packets on the reids server, I found that no connection request was received at all when using apache.
You can know that the problem is caused by apache.
It works under the command line, but not under apache. The first thing I thought of was whether the apache configuration file restricted a certain port, but I couldn't find it.
Finally found the answer on stackoverflow - selinux limits the ports that apache can open (more specifically, the ports that the http service can open).
Solution
/usr/sbin/setsebool httpd_can_network_connect=1
or
Remind me in the future, except for the firewall can stop you, selinux can also stop you , don’t forget.
The above introduces the solution to the problem that PHP cannot open other sockets (permission denied) under Apache, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.