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

dboyd's avatar

sqlite pdoexception connection refused

hello, following the Laravel From Scratch No.13 authenticate your users laracast i followed the instructions, laravel new some-project, php artisan make:auth, touch database/database.sqlite and default database connection set to sqlite, so far so good. after trying, php artisan migrate.. i get the following error...
[PDOException] SQLSTATE[HY000] [2002] Connection refused, checking phpinfo i have the pdo driver for sqlite3 enabled i've been googling this issue for quite some time but can't find any decent information on sqlite :( i was hoping i could make the migrations via homestead like i do when using mysql but unfortunately i'm just getting nothing to migrate(this would be really handy if possible), any helpfull advice appreciated thanks.

0 likes
11 replies
grappling1's avatar

Stuck on this one as well.... Tried following other posts related, nothing seems to be fixing the situation.

stevepop's avatar

I am having the same problem. I set sqlite as my default connection but it seems Laravel is still trying to use Mysql when I reun artisan migrate

  [PDOException]
  SQLSTATE[HY000] [2002] Connection refused

Exception trace:
 () at /Users/steve/devapps/tutorials/laravel/track-model-activity/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:55
 PDO->__construct() at /Users/steve/devapps/tutorials/laravel/track-model-activity/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:55
 Illuminate\Database\Connectors\Connector->createConnection() at /Users/steve/devapps/tutorials/laravel/track-model-activity/vendor/laravel/framework/src/Illuminate/Database/Connectors/MySqlConnector.php:24
 Illuminate\Database\Connectors\MySqlConnector->connect() at /Users/steve/devapps/tutorials/laravel/track-model-activity/vendor/laravel/framework/src/Illuminate/Database/Connectors/ConnectionFactory.php:61
1 like
stevepop's avatar

Okay I have found the answer. Apparently, your .env file values overwrite what is in your database config file. So you need to set your DB_CONNECTION = sqlite. That should work.

5 likes
dboyd's avatar

ok got it sorted

i had to do this "So you need to set your DB_CONNECTION = sqlite" ,(in the .env file)

and change.. 'database' => env('DB_DATABASE', database_path('database.sqlite')), to 'database' => database_path('database.sqlite'),(in the database.php file)

after which php artisan migrate worked

3 likes
Roni's avatar

You could also just remove the env variable DB_DATABASE so you don't have to touch the config file, and database_path is no longer in storage but database. I'm not sure if that's a bug or an update.

jacobfogg's avatar

Ok, so for me, I had to make three code changes to get sqlite to work:

../config/database.php ln 29: 'default' => 'sqlite' ../config/database.php ln 51: 'database' => databae_path('database.sqlite'), ../.env ln 7: DB_CONNECTION = sqlite

1 like
adevade's avatar

I just ran into this problem as well, and after almost 30 minutes of trial and error using tips from answers above I got it working like it's supposed to.

I simply restarted the php artisan serve server after I had created the database/database.sqlite manually. I also ran php artisan config:clear just to clear out any possible cache of the config files.

I'm on Windows 10, PHP 7.1.0 and Laravel 5.3.29.

3 likes
oeswww's avatar

@Adevade thank you. Clearing the config cache helped me. By the way when I ran migration I didn't have this problem with db connection.

kevindees's avatar

I had to run php artisan config:clear and then php artisan serve (again) after my migration to get it to work. Basically, I had to restart the PHP server because of object caching I think.

1 like

Please or to participate in this conversation.