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

erop's avatar
Level 1

$ php artisan migrate to sqlite but "No connection could be made because the target machine actively refused it"

I just started watching "Laravel from scratch" free series. In "Fetching data" episode https://laracasts.com/series/laravel-5-from-scratch/episodes/7 Jeffry tells about using sqlite database. I have exactly the same set up as Jeffry has but after $ php artisan migrate I receive [PDOException] SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it.

I read a lot of answers on the topic. But all of them relates to MySQL, Redis or others "real" databases. Switching from "localhost" to "127.0.0.1" is not the case while using file-based database like sqlite. I try to debug a little and found that migrating script correctly resolves sqlite file path. Everything should by fine but... I tried also MySQL and Postgres - same result. I'm on Windows 10 Pro machine with PHP 7.0.7 TS CLI x64. Any ideas why this happens with sqlite?

0 likes
2 replies
t0mgerman's avatar

Hi, I was having the same issue. If you're currently playing about with the tutorials in a Windows environment and you're not using homestead - then by default you'll have an .env file located at the root of your project, that inside it says:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

After seeing posts here: https://laracasts.com/discuss/channels/laravel/sqlite-pdoexception-connection-refused?page=1 I removed every line except the DB_CONNECTION line and I changed that to

DB_CONNECTION=sqlite

and my config/database.php reads like this on line 29:

'default' => env('DB_CONNECTION', database_path('database.sqlite')),

After that, php artisan migrate worked. Hope this helps!

5 likes

Please or to participate in this conversation.