简体   繁体   中英

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. But in our webserver (different machine), Laravel still can't connected to the database, here's the error:

错误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.

If your MySQL database is on a remote server it may well be one of the following issues:

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 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.

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.

Solved: php can't connect to mysql with error 13 (but command line can)

Now Laravel can connect the DB, By executing: setsebool httpd_can_network_connect=1 in Database Server. 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).

httpd_can_network_connect (HTTPD Service) :: Allow HTTPD scripts and modules to connect to the network.

Run as root:

# setsebool -P httpd_can_network_connect 1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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