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
.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.
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
Set DB_HOST=localhost
and run the following artisan command
php artisan config:clear
it will help you, clear cached config
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.
You might also get this error if you are using sail, and you run
php artisan migrate
instead of:
sail artisan migrate
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With