Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Akeno's avatar

php artisan: "no such file or directory"

Hi,

I'm getting this error if I type in something like php artisan make:model SomeModel

"Error: [PDOException]
SQLSTATE[HY000] [2002] No such file or directory "

This error disappears if I go to my .env file and change the DB_HOST to "127.0.0.1". But then, I get an error from the webpage, that it can't connect to the database:

"SQLSTATE[HY000] [2002] Connection refused"

Any ideas? The internet says I should add the "port" to the mysql-array in database.php. I did, but it didn't help.

Thank you

0 likes
7 replies
Akeno's avatar
APP_ENV=local
APP_DEBUG=true
APP_KEY=w7bcWEaQX1gF8cac8ZT4u3OKWx1cLdH3

DB_HOST=127.0.0.1
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

CACHE_DRIVER=file
SESSION_DRIVER=file

AlanRezende's avatar
Level 2

@Akeno Are you using homestead?

If yes i think you can only call php artisan make:model SomeModel from inside the vm using ssh.

From outside you need to set the port to 33060

RavanScafi's avatar

A workaround is to use DB_HOST=192.168.10.10 (your homestead address) so it can connect to your database from inside and outside homestead.

Akeno's avatar

@AlanRezende From inside homestead it's working :D Thank you

@RavanScafi I don't know. I didn't change anything in the .env file. Unfortunately, the workaround does not work for me :(

Please or to participate in this conversation.