Search code examples
phpmysqllaravellaravel-5.5

Laravel 5.5 SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: No such host is known


After installing Laravel 5.5 for a new project, I get this error:

[Illuminate\Database\QueryException]
  SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: No such host is known.

.env db connection info:

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=lavavelproject
DB_USERNAME=root
DB_PASSWORD=

Dev environment: Windows PHP 7.0


Solution

  • Sometimes the most common issue is using localhost, change this to 127.0.0.1 and it should work for you.

    Sometimes you will have to run:

    php artisan cache:clear and in the rare moments as I have found also running php artisan key:generate