我协助查看了下,确实如此,无论是指定IP、端口的tcp/ip方式连接,或者是用unix socket方式连接,报错信息都类似:
代码如下:
Could not connect: Can't connect to MySQL server on 'MYSQL.SERVER' (13)
而如果用命令行人工连接MySQL,则一切正常。
问题看起来像是php(with apache)不被允许连接MySQL,但是防火墙也没有。想来想去,唯有SELinux的因素会导致这个问题。
代码如下:
getsebool -a|grep -i httpd
可以看到这里设置了httpd进程的许可模式,再仔细看一下,有一个选项:
代码如下:
getsebool -a|grep -i httpd_can_network_connect
httpd_can_network_connect --> off
代码如下:
setsebool -P httpd_can_network_connect=1
代码如下:
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
#SELINUX=enforcing
#把设置改为disabled
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
代码如下:
[root@imysql~]# setenforce 0
setenforce: SELinux is disabled
Copyright © 2019- gamedaodao.net 版权所有 湘ICP备2024080961号-6
违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务