Smiley Happy Coder

SQLSTATE[HY000] [2002] Connection refused with SQLite in Laravel 5

I’ve come across this one a couple of times over the last few months, each time, I’ve managed to dig around and fix it but I thought for my own sanity I’ll write it down and where better than here.

The issue comes about when I’ve just started a new Laravel project. I’ve set up all the authentication etc and run my migrations to create the user tables etc.
Now when I try to register for the first time, I can’t create the user record.

Sanity Check

Just to make sure, before I make the big reveal, lets check a couple of things.

  1. Check the .env file to make sure you’re telling Laravel to use SQLite rather than MySQL which is the standard.
  2. Jump into the config/database.php file and ensure that the name of the database file is correct.
  3. Check the database file actually exists, if you have run some migrations you won’t have been able to get this far without the file being in place

So, out with it!

The big reveal I found was simply that I needed to restart php artisan serve. For some reason Artisan is perfectly able to talk to the database but the browser is not without a reload.
That is the part that utterly baffled me. Why was Artisan okay to migrate but the app cannot perform an INSERT.

So there we have it, I hope that helps someone else out there too!