DedenB
DedenB

Reputation: 50

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:

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.

Upvotes: 1

Views: 1315

Answers (3)

Suraj
Suraj

Reputation: 2277

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

Upvotes: 0

DedenB
DedenB

Reputation: 50

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?

Upvotes: 0

AlexR1712
AlexR1712

Reputation: 59

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.

Upvotes: 3

Related Questions