If you ever saw this error message in Laravel:
"SQLSTATE[HY000]  No such file or directory"
most likely you have problem with configuration of database connection in your
To fix it you have to be sure that correct DB_HOST is set in env file and the value of it should be correct. If you are in your local environment try to change from localhost to 127.0.0.1
DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 ...
And after you make this change do not forget to clear the config cache
php artisan config:clear
But in some cases, this could also be wrong. And after you make this change you will get another error:
SQLSTATE[HY000]  Connection refused (SQL: select * from `sessions` where `id` = ...
This error is not really explaining the real problem, but the main problem now is that your DB_HOST IP address is definitely wrong and Laravel actually cannot make connection to this database. In order to fix it double check your DB host IP and port, and update it accordingly.
If you are using XAMPP, open it and check on which IP is working because latest version are using different local IP:
In this case you have to change DB_HOST to
do not forget to run
php artisan config:clear to apply the change.
And boom the error is gone!
If you are using some Docker or some other virtual development environment, double check the MySQL IP and port and set it correctly in .
So, basically this can be fixed in these 3 steps:
- Check the correct IP address of your MySQL (or just switch localhost to 127.0.0.1)
- update DB_HOST in .env file
- run php artisan config:clear to clear the cache and apply your change