Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known

I keep this while running php artisan migrate

SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known

My Environment

  • Laravel Framework version 5.1.20 (LTS)
  • Laravel Installer version 1.2.0
  • PHP 5.6.14 (cli) (built: Oct 2 2015 08:55:56)
  • mysql Ver 14.14 Distrib 5.6.24, for osx10.10 (x86_64)

.env file

APP_ENV=local
APP_URL=http://localhost/
APP_DEBUG=true
APP_KEY=****

DB_HOST=http://localhost/
DB_DATABASE=name-local
DB_USERNAME=root
DB_PASSWORD=
UNIX_SOCKET = /tmp/mysql.sock

That data-base name-local is exist in my local database.

Any hints / suggestions will be a huge help for me.

like image 562
code-8 Avatar asked Oct 21 '15 13:10

code-8


5 Answers

Check your DB_HOST on your .env file

DB_HOST=http://localhost/ --> DB_HOST=localhost


Result:

I can migrate peacefully now.

php artisan migrate
Migration table created successfully.
Migrated: 2014_10_12_000000_create_users_table
like image 85
code-8 Avatar answered Nov 16 '22 05:11

code-8


Set DB_HOST=localhost and run the following artisan command

php artisan config:clear it will help you, clear cached config

like image 35
Suresh Velusamy Avatar answered Nov 16 '22 05:11

Suresh Velusamy


I finally figured out what was causing this error for me. I'm using docker but I wasn't running php artisan migrate from the shell in the container. I was just running it in Terminal after navigating to the laravel project folder. Go to your docker dashboard and launch the CLI for the laravel container in the image for your project. Then run the migrate command.

like image 19
Andrew Avatar answered Nov 16 '22 06:11

Andrew


You might also get this error if you are using sail, and you run php artisan migrate instead of:

sail artisan migrate

like image 9
James Alvarez Avatar answered Nov 16 '22 05:11

James Alvarez


I had the same problem while running Laravel from DDEV.

Solution: run "php artisan migrate" within your DDEV container.

user@ddev-project:  ddev ssh

user@ddev-project:/var/www/html$ php artisan migrate

That should solve the issue.

like image 3
mikenificent Avatar answered Nov 16 '22 05:11

mikenificent