简体   繁体   English

远程MySQL不使用Laravel Config

[英]Remote MySQL not working with Laravel Config

Our database server has grant access to all local ip's with user root and it works well to access them via cli in all local IP. 我们的数据库服务器具有对用户root的所有本地ip的授权访问权限,并且可以通过所有本地IP中的cli访问它们。 But in our webserver (different machine), Laravel still can't connected to the database, here's the error: 但是在我们的webserver(不同的机器)中,Laravel仍然无法连接到数据库,这里是错误:

错误PHP

I've tried to clear cache, reinstall the Laravel (install composer, generate new key etc.) change db config drive to sqli, it still error connecting the remote db, but why the DB works when I querying the DB via tinker on that machine, this is so unusual. 我试图清除缓存,重新安装Laravel(安装编辑器,生成新密钥等)将db config驱动器更改为sqli,它仍然错误连接远程数据库,但为什么数据库工作时我通过修补程序查询数据库机器,这太不寻常了。

If your MySQL database is on a remote server it may well be one of the following issues: 如果您的MySQL数据库位于远程服务器上,则可能是以下问题之一:

Firewall Block , the server with the MySQL service may be behind a firewall that is set to block external access to the port that MySQL operates on. 防火墙块 ,具有MySQL服务的服务器可能位于防火墙后面,该防火墙设置为阻止对MySQL运行的端口的外部访问。

MySQL User Permissions , if the MySQL service is not sat behind a firewall then the next cause may be that the user has only localhost access permissions. MySQL用户权限 ,如果MySQL服务不在防火墙后面,那么下一个原因可能是用户只具有localhost访问权限。

You should try to log in to your remote server and, from there, connect to your database via some shell command to verify you actually can. 您应该尝试登录到远程服务器,并从那里通过一些shell命令连接到您的数据库,以验证您实际可以。

Solved: php can't connect to mysql with error 13 (but command line can) 解决: php无法连接到mysql,错误13(但命令行可以)

Now Laravel can connect the DB, By executing: setsebool httpd_can_network_connect=1 in Database Server. 现在,Laravel可以通过在数据库服务器中执行: setsebool httpd_can_network_connect=1来连接数据库。 But I still don't understand why. 但我仍然不明白为什么。 Is there any reasonable explanation? 有没有合理的解释?

Security-Enhanced Linux (SELinux) is a Linux kernel security module that provides a mechanism for supporting access control security policies, including United States Department of Defense–style mandatory access controls (MAC). 安全增强型Linux(SELinux)是一个Linux内核安全模块,它提供了一种支持访问控制安全策略的机制,包括美国国防部式的强制访问控制(MAC)。

httpd_can_network_connect (HTTPD Service) :: Allow HTTPD scripts and modules to connect to the network. httpd_can_network_connect(HTTPD服务) ::允许HTTPD脚本和模块连接到网络。

Run as root: 以root身份运行:

# setsebool -P httpd_can_network_connect 1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM