Laravel and “Connection refused” problem

Say you clone a Laravel project and need to perform database migrations. So you do the following:

php artisan migrate

And the result is this:

SQLSTATE[HY000] [2002] Connection refused

And you think right away “Right, I forgot to configure my database properly”. But even after updating the config/database.php file or the .env file the result remains the same.

For me the solution was adding the port number. First I add it to the .env file:


And then fetch it in the config:

'port' => env('DB_PORT', 8889)