PHPackages                             er-dhruvmishra/laravel-sqlite-ffi - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. er-dhruvmishra/laravel-sqlite-ffi

ActiveLibrary[Database &amp; ORM](/categories/database)

er-dhruvmishra/laravel-sqlite-ffi
=================================

Drop-in SQLite driver for Laravel using PHP FFI — no pdo\_sqlite or sqlite3 extension required. Zero code changes needed.

v1.1.4(3mo ago)010MITPHPPHP ^8.1

Since Apr 7Pushed 3mo agoCompare

[ Source](https://github.com/Er-DhruvMishra/laravel-sqlite-ffi)[ Packagist](https://packagist.org/packages/er-dhruvmishra/laravel-sqlite-ffi)[ Docs](https://github.com/erdhruvmishra/laravel-sqlite-ffi)[ RSS](/packages/er-dhruvmishra-laravel-sqlite-ffi/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (5)Dependencies (2)Versions (6)Used By (0)

Laravel SQLite FFI
==================

[](#laravel-sqlite-ffi)

A **drop-in replacement** for Laravel's SQLite database driver with a 3-tier fallback chain. Works even when `pdo_sqlite` and FFI are both unavailable.

**Zero code changes needed** — install via Composer and your existing `'driver' => 'sqlite'` configuration works immediately.

Why?
----

[](#why)

Some hosting environments or custom PHP builds don't include the `pdo_sqlite` extension. This package provides the same SQLite functionality through multiple backends:

TierBackendSpeedRequires1Native `pdo_sqlite`FastestPHP extension2FFI (`libsqlite3`)Near-nativeext-ffi + `ffi.enable=true`3`sqlite3` CLI binarySlower (IPC)Binary on system or auto-downloadedThe package auto-detects the best available backend. The CLI tier **auto-downloads** `sqlite3` from sqlite.org on first use if not found on the system.

- Works with Laravel 10, 11, and 12
- Supports migrations, Eloquent, Query Builder, Schema Builder, transactions, cursors
- Cross-platform: Linux, macOS, Windows
- Same behavior as the native driver — your application code doesn't change

Requirements
------------

[](#requirements)

RequirementDetailsPHP&gt;= 8.1Laravel10.x / 11.x / 12.x**At least one of:**pdo\_sqlitePHP extension (Tier 1, best performance)ext-ffi + libsqlite3FFI extension with `ffi.enable=true` (Tier 2)sqlite3 binarySystem binary or auto-downloaded (Tier 3)Installation
------------

[](#installation)

### 1. Install the package

[](#1-install-the-package)

```
composer require er-dhruvmishra/laravel-sqlite-ffi
```

Laravel auto-discovers the service provider. No manual registration needed.

### 2. Use it

[](#2-use-it)

No changes to your code or config. The standard Laravel SQLite configuration works as-is:

```
// config/database.php
'sqlite' => [
    'driver' => 'sqlite',
    'database' => database_path('database.sqlite'),
    'prefix' => '',
    'foreign_key_constraints' => true,
],
```

The package automatically picks the best available backend.

### 3. Optional: Enable specific backends

[](#3-optional-enable-specific-backends)

**For FFI (Tier 2):**

```
; /etc/php/8.x/cli/conf.d/20-ffi.ini
extension=ffi.so
ffi.enable=true
```

**For CLI (Tier 3):**

```
# Install sqlite3 binary (or let the package auto-download it)
sudo apt install sqlite3        # Debian/Ubuntu
sudo yum install sqlite         # RHEL/CentOS
brew install sqlite             # macOS
```

How It Works
------------

[](#how-it-works)

```
Your Laravel App
       |
  'driver' => 'sqlite'
       |
  [SqliteFFIServiceProvider]       ← auto-discovered
       |
  [PdoFactory]                     ← picks best available backend
       |
  ┌────┴────────────┬──────────────────┐
  │                 │                  │
Tier 1           Tier 2             Tier 3
native PDO    SqlitePDO(FFI)    SqliteCliPDO
  │                 │                  │
pdo_sqlite     libsqlite3.so     sqlite3 binary
extension      via PHP FFI       via proc_open

```

Backend Priority Configuration
------------------------------

[](#backend-priority-configuration)

By default, the fallback order is: **native → ffi → cli**

You can customize this in three ways:

### Force a specific backend

[](#force-a-specific-backend)

In `config/database.php`:

```
'sqlite' => [
    'driver' => 'sqlite',
    'database' => database_path('database.sqlite'),
    'sqlite_backend' => 'ffi',   // 'native', 'ffi', or 'cli'
],
```

Or via environment variable:

```
SQLITE_BACKEND=ffi
```

### Custom fallback order

[](#custom-fallback-order)

In `config/database.php`:

```
'sqlite' => [
    'driver' => 'sqlite',
    'database' => database_path('database.sqlite'),
    'sqlite_priority' => ['cli', 'ffi', 'native'],  // try CLI first
],
```

Or via environment variable:

```
SQLITE_PRIORITY=cli,ffi,native
```

### Set default priority in code

[](#set-default-priority-in-code)

```
use ErDhruvMishra\SqliteFFI\PdoFactory;

// In a service provider's register() method:
PdoFactory::setDefaultPriority(['ffi', 'cli', 'native']);
```

### Check which backend is active

[](#check-which-backend-is-active)

```
use ErDhruvMishra\SqliteFFI\PdoFactory;

echo PdoFactory::activeTier();  // 'native', 'ffi', 'cli', or 'none'
```

TNTSearch Compatibility
-----------------------

[](#tntsearch-compatibility)

If you use [teamtnt/tntsearch](https://github.com/teamtnt/tntsearch), it calls `new PDO('sqlite:...')` directly which fails without `pdo_sqlite`. This package includes a drop-in engine replacement:

```
$tnt->loadConfig([
    'driver'   => 'mysql',
    'host'     => config('database.connections.mysql.host'),
    'database' => config('database.connections.mysql.database'),
    'username' => config('database.connections.mysql.username'),
    'password' => config('database.connections.mysql.password'),
    'storage'  => storage_path('tnt_indices') . '/',
    'engine'   => \ErDhruvMishra\SqliteFFI\Compat\TntSearchEngine::class,
]);
```

The `TntSearchEngine` uses the same 3-tier fallback as the main driver.

Configuration Options
---------------------

[](#configuration-options)

All standard Laravel SQLite config options are supported, plus:

```
'sqlite' => [
    'driver' => 'sqlite',
    'database' => database_path('database.sqlite'),
    'prefix' => '',
    'foreign_key_constraints' => true,        // PRAGMA foreign_keys = ON
    'journal_mode' => 'wal',                  // PRAGMA journal_mode = wal
    'busy_timeout' => 5000,                   // PRAGMA busy_timeout (ms)
    'sqlite_backend' => null,                 // Force: 'native', 'ffi', 'cli'
    'sqlite_priority' => null,                // Custom order: ['ffi', 'cli']
],
```

### Environment variables

[](#environment-variables)

VariableDescriptionExample`SQLITE_BACKEND`Force a specific backend`ffi``SQLITE_PRIORITY`Custom fallback order (comma-separated)`cli,ffi,native``SQLITE_FFI_LIBRARY_PATH`Custom path to `libsqlite3.so``/opt/lib/libsqlite3.so``SQLITE3_BINARY_PATH`Custom path to `sqlite3` binary`/opt/bin/sqlite3`Supported Features
------------------

[](#supported-features)

- **CRUD** — SELECT, INSERT, UPDATE, DELETE with parameter binding
- **Transactions** — BEGIN, COMMIT, ROLLBACK, savepoints
- **Migrations** — `php artisan migrate` works normally
- **Schema Builder** — create/alter/drop tables, indexes, foreign keys
- **Eloquent ORM** — models, relationships, eager loading
- **Query Builder** — where, join, aggregate, pagination
- **Cursors** — memory-efficient iteration via generators
- **NULL handling** — proper NULL value support
- **BLOB support** — binary data storage
- **Foreign key constraints** — via `foreign_key_constraints` config
- **WAL mode** — via `journal_mode` config
- **Busy timeout** — via `busy_timeout` config

Compatibility
-------------

[](#compatibility)

FeatureNativeFFICLI`DB::connection('sqlite')`YesYesYes`Schema::create()` / `drop()`YesYesYesQuery Builder CRUDYesYesYesEloquent modelsYesYesYesTransactions + rollbackYesYesYes`php artisan migrate`YesYesYesMultiple connectionsYesYesYesIn-memory (`:memory:`)YesYesYes`lastInsertId()`YesYesYesServer-side prepared statementsYesYesNo\*TNTSearch indexingYesYesYes\* CLI tier uses client-side parameter escaping (safe, but slightly different execution model).

Troubleshooting
---------------

[](#troubleshooting)

### "No SQLite backend available"

[](#no-sqlite-backend-available)

At least one backend must be available. Check:

```
# Check what's available
php -r "
echo 'pdo_sqlite: ' . (extension_loaded('pdo_sqlite') ? 'YES' : 'no') . PHP_EOL;
echo 'FFI: ' . (extension_loaded('FFI') ? 'YES' : 'no') . PHP_EOL;
echo 'ffi.enable: ' . ini_get('ffi.enable') . PHP_EOL;
echo 'sqlite3 CLI: '; exec('which sqlite3 2>/dev/null', \$o, \$c); echo \$c === 0 ? 'YES' : 'no'; echo PHP_EOL;
"
```

### "FFI API is restricted by ffi.enable"

[](#ffi-api-is-restricted-by-ffienable)

FFI is loaded but `ffi.enable` is set to `preload` (default) instead of `true`:

```
; Change from preload to true
ffi.enable=true
```

Restart PHP-FPM after changing:

```
sudo systemctl restart php8.x-fpm
```

### "libsqlite3 shared library not found"

[](#libsqlite3-shared-library-not-found)

Install the SQLite3 library:

```
# Debian/Ubuntu
sudo apt install libsqlite3-0

# RHEL/CentOS
sudo yum install sqlite-libs

# macOS
brew install sqlite
```

### "sqlite3 binary not found"

[](#sqlite3-binary-not-found)

For CLI tier, install sqlite3 or let the package auto-download it:

```
# Debian/Ubuntu
sudo apt install sqlite3

# Or set a custom path
export SQLITE3_BINARY_PATH=/path/to/sqlite3
```

The package will also auto-download from sqlite.org on first use if the `bin/` directory is writable.

License
-------

[](#license)

MIT License. See [LICENSE](LICENSE) for details.

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance79

Regular maintenance activity

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

5

Last Release

109d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5cc2b09626bc0586c74fa9df2d3e361a7780d994c5b090d9b194aa05902b8697?d=identicon)[er.dhruvmishra](/maintainers/er.dhruvmishra)

---

Top Contributors

[![Er-DhruvMishra](https://avatars.githubusercontent.com/u/14871013?v=4)](https://github.com/Er-DhruvMishra "Er-DhruvMishra (7 commits)")

---

Tags

databaseffilaravelpdophpsqlitelaraveldatabasesqlitepdodriverffidrop-in

### Embed Badge

![Health badge](/badges/er-dhruvmishra-laravel-sqlite-ffi/health.svg)

```
[![Health](https://phpackages.com/badges/er-dhruvmishra-laravel-sqlite-ffi/health.svg)](https://phpackages.com/packages/er-dhruvmishra-laravel-sqlite-ffi)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.4M98](/packages/mongodb-laravel-mongodb)[psalm/plugin-laravel

Psalm plugin for Laravel

3345.3M347](/packages/psalm-plugin-laravel)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8793.2M25](/packages/yajra-laravel-oci8)[glushkovds/phpclickhouse-laravel

Adapter of the most popular library https://github.com/smi2/phpClickHouse to Laravel

2051.5M2](/packages/glushkovds-phpclickhouse-laravel)[ntanduy/cloudflare-d1-database

Cloudflare D1 database driver for Laravel — full Eloquent &amp; Query Builder support.

267.8k](/packages/ntanduy-cloudflare-d1-database)[aimeos/laravel-nestedset

Nested Set Model for Laravel

3714.4k7](/packages/aimeos-laravel-nestedset)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
