This question has been asked before but none of the solutions have worked. I am using:
- OS X 11.0.1
- PHP 7.4.9
- mySQL 8.0.20
- Laravel Framework 8.18.1
I am following a tutorial and I am trying to run some code to connect to the DB.
I am able to connect to the database via Adminer.php and my SQL client, but when trying to access the database, I get:
Illuminate\Database\QueryException SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known (SQL: select
name
fromproducts
whereid
= 4 limit 1)
My env file:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=storify
DB_USERNAME=root
DB_PASSWORD=rootroot
My guess is that it cannot connect to the local DB instance. I have tried setting the host to 127.0.0.1:3306. I have also tried to edit the database.php to troubleshoot further but the message persists:
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => '127.0.0.1',
'database' => env('DB_DATABASE', 'forge'),
'username' => 'root',
'password' => 'rootroot',
'unix_socket' => env('DB_SOCKET', ''),
I also run this command every time I make a change:
php artisan cache:clear
If I change the host to something obviously incorrect, I still get the same error, so Laravel is definitely not finding the host for some weird reason.
My hosts file only contains:
127.0.0.1 localhost localhost.local
phpAdmin screen:
Any ideas on how to troubleshoot this?