'Laravel connection timed out

I've searched a loot on google about this problem and I tried everything. I have a database of a game from a hosting and I bought another webhost (shared hosting) from another company.

I have Laravel 7 on my website and I want to display all users informations from database and many other things.

The problem that i'm facing, is that, I need to access the database remote OUT (which I spoke with the support of the shared hosting and they said that they allow it), but still I get this error:

[previous exception] [object] (PDOException(code: 2002): SQLSTATE[HY000] [2002] Connection timed out at /home/kirosne1/web/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70)

The page is render (for example: login page) but when I click the 'login button' to check if the user exist, I wait for aboout 30 seconds and it gets me error 404 and in laravel.log is the above error.

My .env is something like this: (example):

DB_CONNECTION=mysql
DB_HOST=195.205.39.83
DB_PORT=3306
DB_DATABASE=hji2jsad232
DB_USERNAME=hji2jsad232
DB_PASSWORD=23sadsadsa

I tried to connect from a local mysql on the shared hosting i bought, and is working, but remote OUT is not.

I tried changing the php version from cpanel, also to clear the caches and it didn't work.

What should I do?



Solution 1:[1]

You should manually change credentials of DB in bootstrap/cache/config.php Looks like this:

'mysql' => 
  array (
    'driver' => 'mysql',
    'url' => NULL,
    'host' => '127.0.0.1',
    'port' => '3306'
        ),

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1