Reputation: 674
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
Upvotes: 2
Views: 34604
Reputation: 2619
On your application .env should be pointing to the IP of your database. Your database is the same server as your Laravel application, it should be:
.env
DB_HOST=127.0.0.1
Upvotes: 0
Reputation: 647
I had same problem. The solution was to change DB_HOST=mariadb
to DB_HOST=localhost
.
If it matters, my localhost is 127.0.0.1.
Anyway, for my project and my PC config, the problem comes from Apache (XAMP), I think.
My project run in Docker containers.
I put in my ".env" file above two lines,
DB_HOST=mariadb
#DB_HOST=localhost
.
The last line (localhost) is commented and not change when I run the project.
For running php artisan
commands, I'll deactivate "mariadb" and activate "localhost".
Simple trick to not change much.
Upvotes: 0
Reputation: 35
Faced the same issue, changing DB_HOST=mysql
to DB_HOST=localhost
solved my problem.
Upvotes: 0
Reputation: 2645
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
Upvotes: 15
Reputation: 5896
Try to clear cache by terminal:
php artisan config:cache
Do it always when you change config file.
Upvotes: 19