use 192.168.10.10 for DB_HOST
DB_HOST=192.168.10.10
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi, first time posting here. My issue is this: I want to use Homestead. I follow the instructions religiously, create my migrations, set my variables exactly as described:
'mysql' => [
'driver' => 'mysql',
'host' => $_ENV['DB_HOST'],
'database' => $_ENV['DB_DATABASE'],
'username' => $_ENV['DB_USERNAME'],
'password' => $_ENV['DB_PASSWORD'],
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
],
APP_ENV=local
APP_DEBUG=true
APP_KEY=SomeRandomString
DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
..then I get the homestead box going with homestead up. Now I want to run my migrations and populate my database, so I run
php artisan migrate
...and i get:
exception 'PDOException' with message 'SQLSTATE[HY000] [2002] No such file or directory' in /Users/lazimac/Developer/forge/experiments/donkey/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:47
Stack trace:
#0 /Users/lazimac/Developer/forge/experiments/donkey/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php(47): PDO->__construct('mysql:host=loca...', 'homestead', 'secret', Array)
The actual error is much longer. So what's the problem? It has to do with the ports being forwarded on the homestead box. The normal "php artisan migrate" function being called from here apparently will not work. If I then change my host to
APP_ENV=local
APP_DEBUG=true
APP_KEY=SomeRandomString
DB_HOST=localhost:33060
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
(Note the port added to the localhost), I can run my migration!
But then the application can't connect to the database, because it is running inside the virtual machine. So when I try to go to a page I get another PDO connection error.
So it seems that it's one or the other: either you configure your app so you can run commands from the normal terminal (by setting port 33060), or you can configure you app to access the DB from within.
My question, for all that long explanation, is how can I do both? I would like to use homestead but still be able to run artisan commands on the DB. Has anyone else figured this out?
Thanks!
Please or to participate in this conversation.