使用环境 centos 8 LNMP wordpress
先说结论:系统重启后没有关闭selinux
因为维护主机,所以重启了一下虚拟机,结果wp就没法正常访问了,一直提示数据库连接异常。在排查了数据库和nginx无果之后,想到了去系统的message查下报错信息。果然发现了端倪
Mar 7 19:45:14 host setroubleshoot[2219]: SELinux is preventing php-fpm from name_connect access on the tcp_socket port 3306.#012#012***** Plugin catchall_boolean (47.5 confidence) suggests ******************#012#012If you want to allow httpd to can network connect#012Then you must tell SELinux about this by enabling the 'httpd_can_network_connect' boolean.#012#012Do#012setsebool -P httpd_can_network_connect 1#012#012***** Plugin catchall_boolean (47.5 confidence) suggests ******************#012#012If you want to allow httpd to can network connect db#012Then you must tell SELinux about this by enabling the 'httpd_can_network_connect_db' boolean.#012#012Do#012setsebool -P httpd_can_network_connect_db 1#012#012***** Plugin catchall (6.38 confidence) suggests **************************#012#012If you believe that php-fpm should be allowed name_connect access on the port 3306 tcp_socket by default.#012Then you should report this as a bug.#012You can generate a local policy module to allow this access.#012Do#012allow this access for now by executing:#012# ausearch -c 'php-fpm' --raw | audit2allow -M my-phpfpm#012# semodule -X 300 -i my-phpfpm.pp#012
这就很明显提示selinux阻止了php-fpm建立的mysql连接。关闭selinux之后一切正常。