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

AlokDev's avatar

SQLITE Database throw error could not find driver (SQL: PRAGMA foreign_keys = ON;)

Hello Everyone,

I am new in laravel and ubantu. i am trying to migrate my database using php artisan migrate command but i get error. i have already created a database/database.sqlite file. my .env file DB_CONNECTION=sqlite

BROADCAST_DRIVER=log CACHE_DRIVER=file QUEUE_CONNECTION=sync SESSION_DRIVER=file SESSION_LIFETIME=120

Error:- PHP Warning: PHP Startup: Unable to load dynamic library 'pdo_sqlite' (tried: /usr/lib/php/20170718/pdo_sqlite (/usr/lib/php/20170718/pdo_sqlite: cannot open shared object file: No such file or directory), /usr/lib/php/20170718/pdo_sqlite.so (/usr/lib/php/20170718/pdo_sqlite.so: cannot open shared object file: No such file or directory)) in Unknown on line 0

Illuminate\Database\QueryException : could not find driver (SQL: PRAGMA foreign_keys = ON;)

at /var/www/html/frest-bootstrap-admin-template-html/frest-laravel-admin-template/vendor/laravel/framework/src/Illuminate/Database/Connection.php:669 665| // If an exception occurs when attempting to run a query, we'll format the error 666| // message to include the bindings with SQL, which will make this exception a 667| // lot more helpful to the developer instead of just the database's errors. 668| catch (Exception $e) {

669| throw new QueryException( 670| $query, $this->prepareBindings($bindings), $e 671| ); 672| } 673|

Exception trace:

1 Doctrine\DBAL\Driver\PDOException::("could not find driver") /var/www/html/frest-bootstrap-admin-template-html/frest-laravel-admin-template/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:31

2 PDOException::("could not find driver") /var/www/html/frest-bootstrap-admin-template-html/frest-laravel-admin-template/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:27

Please use the argument -v to see more details.

Whoops\Exception\ErrorException : PHP Startup: Unable to load dynamic library 'pdo_sqlite' (tried: /usr/lib/php/20170718/pdo_sqlite (/usr/lib/php/20170718/pdo_sqlite: cannot open shared object file: No such file or directory), /usr/lib/php/20170718/pdo_sqlite.so (/usr/lib/php/20170718/pdo_sqlite.so: cannot open shared object file: No such file or directory))

at Unknown:0 1|

Exception trace:

1 Whoops\Run::handleError("PHP Startup: Unable to load dynamic library 'pdo_sqlite' (tried: /usr/lib/php/20170718/pdo_sqlite (/usr/lib/php/20170718/pdo_sqlite: cannot open shared object file: No such file or directory), /usr/lib/php/20170718/pdo_sqlite.so (/usr/lib/php/20170718/pdo_sqlite.so: cannot open shared object file: No such file or directory))", "Unknown") /var/www/html/frest-bootstrap-admin-template-html/frest-laravel-admin-template/vendor/filp/whoops/src/Whoops/Run.php:408

2 Whoops\Run::handleShutdown() [internal]:0

Please help me to solve this.

0 likes
30 replies
Sti3bas's avatar
Sti3bas
Best Answer
Level 53

sudo apt-get install php-sqlite3

72 likes
AlokDev's avatar

@sti3bas thanks now it works.

PHP Warning: PHP Startup: Unable to load dynamic library 'pdo_sqlite' (tried: /usr/lib/php/20170718/pdo_sqlite (/usr/lib/php/20170718/pdo_sqlite: cannot open shared object file: No such file or directory), /usr/lib/php/20170718/pdo_sqlite.so (/usr/lib/php/20170718/pdo_sqlite.so: undefined symbol: php_pdo_unregister_driver)) in Unknown on line 0 Migration table created successfully. Migrating: 2014_1012000000_create_users_table Migrated: 2014_1012000000_create_users_table (0.01 seconds) Migrating: 2014_10_12_100000create_password_resets_table Migrated: 2014_1012_100000create_password_resets_table (0 seconds) Migrating: 201908_19000000create_failed_jobs_table Migrated: 201908_19000000_create_failed_jobs_table (0 seconds)

1 like
tomasosho's avatar

It's best to use full SQL rather than SQLite. SQLite increases exponentially in size.

jkemboe's avatar

This worked for me Check PHP version you are using 'php -v' Then run .. sudo apt-get install php(version no)-sqlite3 In my case in was sudo apt-get install php7.4-sqlite3

3 likes
asciimo_joe's avatar

I am using php 8.0.11 with laravel 8. I have tried every possible combination: sudo apt-get php8-sqlite3 | php8.0-sqlite3 | php8.0.11-sqlite3 but none of these worked. Any way of proceeding forward? Would it be compatible with php7.4-sqlite3?

radd2004's avatar

For those using windows;

Navigate to the php.ini file(-C:\php\php.ini)

Enable the following:

;extension=pdo_sqlite by removing the /;/ should look like this 			 extension=pdo_sqlite

;extension=sqlite3 should be extension=sqlite3 without the ; symbol
6 likes
Yevh's avatar

On linux same thing -> /etc/php/php.ini

@radd2004 Thank you, I often forget about this one !

0000's avatar

For Laravel 9 on Alpine Linux, use the PDO driver:

apk add php8-pdo_sqlite

abms1's avatar

@abenu Run the following command to check if sqlite is not installed:

php --ini | grep sqlite

if the above command returns nothing, then you need to install sqlite extension.

Check which php version is installed first:

php --version

In my case, the above returns the following:

PHP 8.2.13 (cli) (built: Nov 24 2023 08:46:50) (NTS)

so to install the right version of sqlite , I need to install php8.2-sqlite:

sudo apt install php8.2-sqlite3
1 like
Tray2's avatar

@GamalielGhelli No, sudo is a unix/linux command used to elevate the current users rights temporarily.

If you are using windows, you don't need to install SQLite, just use Laravel Herd.

Please or to participate in this conversation.