连接到数据库时的Laravel连接超时

I am moving an application from my development machine to a test server. When connecting to my local development mysql database everything works as expected. When attempting to connect to our test server, the requests time out after 45 seconds and a 500 error is returned.

I tested that the servers can communicate and php can get results by using the basic mysqli php functionality, and results are returned as expected:

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$sql = "SELECT * FROM users";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo var_export($row, true);
    }
} else {
    echo "0 results";
}
$conn->close();

The following both fail and hit timeout limits in laravel:

$users = DB::table('users')->get();

$users = User::all();

Thoughts? Ideas? Opinions?

I had the same issue. I did var_dump(DB::connection()); and found out that the host value was wrong because a wrong .env file was loaded.