litebucket.dev v0.2.2
laravel-litebucket 0.2.2 on crates.io

Durable SQLite directly on S3, R2, and Laravel Cloud Object Storage.

  • No sidecar.
  • No proxy.
  • No Postgres.

An in-process SQLite VFS for Laravel for Rust. Your app keeps its sub-millisecond local reads; every commit lands in your bucket as an immutable, fenced, optionally encrypted object.

One line in main.rs.
Zero changes to your queries.

.with_litebucket() plugs a SQLite VFS into laravel-rust. Migrations, db::query!, transactions and Route Model Binding work unchanged; the database simply lives in your bucket.

  • Configured from FILESYSTEM_*, AWS_* or LITEBUCKET_*
  • Survives redeploys, hibernation and container stops
  • Pairs with tenanted.dev for a database per tenant
Quick start
src/main.rs
use std::process::ExitCode;
use laravel_litebucket::prelude::*;

fn main() -> ExitCode {
    laravel::Application::configure()
        .with_litebucket()
        .with_routing(|routing, _| {
            routing.health("/up");
            routing.routes(|route| {
                route.get("/posts", list_posts);
                route.post("/posts", create_post);
            });
        })
        .run()
}
Cold bootLazy 4 KB Range GETs

Open a multi-GB database without downloading it. Pages arrive on demand.

FencingIf-None-Match: *

Each commit is a create-only write. Two writers can't both win a transaction.

SecurityAES-256-GCM per page

Encrypted before upload, with a derived key per tenant.

RecoveryPITR & zero-copy clones

Query any recent commit. Fork production inside the bucket.

01Quick start

Up and running in one line.

Add the crate, call .with_litebucket(), attach a bucket. Your existing queries, transactions and migrations now run on durable object storage.

Install

Shell
cargo add laravel-litebucket

# Optional: the standalone ops CLI
cargo install litebucket

# Optional: coding-agent skill (version-matched docs + rules)
npx skills@latest add cole-robertson/litebucket --skill laravel-litebucket

Enable it

Import the WithLiteBucket trait and add one line to Application::configure():

src/main.rs
use std::process::ExitCode;
use laravel_litebucket::prelude::*;

fn main() -> ExitCode {
    laravel::Application::configure()
        .with_litebucket()
        .with_routing(|routing, _| {
            routing.health("/up");
            routing.routes(|route| {
                route.get("/posts", list_posts);
                route.post("/posts", create_post);
            });
        })
        .run()
}

.with_litebucket() registers a service provider that:

  • Always registers litebucket as a named SQLite VFS, so explicit ?vfs=litebucket URLs work next to a central Postgres or local database.
  • With LITEBUCKET_VFS=1, also makes it the process-default SQLite VFS, so laravel::db::query!, transactions and migrations run against the bucket. If no default connection is configured, it adds one.
  • Registers the 11 sqlite:* Artisan commands.
  • Installs a SIGTERM hook that flushes every open database and releases its write lease before the container exits.
  • Prepends WriteForwardingMiddleware when LITEBUCKET_ADVERTISE_ADDR is set.

Without LITEBUCKET_VFS, local SQLite connections get production pragmas instead (WAL, synchronous = NORMAL, busy_timeout = 5000, foreign_keys = ON). Postgres and MySQL connections are never touched.

Customize fluently

Prefer code over env vars? .with_litebucket_using hands you a LiteBucketBuilder. It starts from the environment, so anything you don't set keeps its env value or default.

src/main.rs
use laravel_litebucket::prelude::*;

laravel::Application::configure()
    .with_litebucket_using(|b| {
        b.sync_mode(SyncMode::Batched)
            .disk_cache_mb(64)
            .write_lease(true)
            .compact_every(32);
    })
    .with_routing(|routing, _| { /* ... */ })
    .run()
Builder methodDefaultWhat it controls
sync_mode(SyncMode)BatchedBatched or Strict commits. Env: LITEBUCKET_SYNC_MODE.
write_lease(bool)trueFenced single-writer lease in write_lock.json. Env: LITEBUCKET_WRITE_LEASE.
disk_cache_mb(usize)64L2 NVMe page cache budget; 0 disables. Env: LITEBUCKET_DISK_CACHE_MB.
refresh_interval_ms(u64)500Background catch-up interval for readers. Env: LITEBUCKET_REFRESH_MS.
compact_every(u64)32Auto-compact into snapshot chunks every N transactions; 0 disables. Env: LITEBUCKET_COMPACT_EVERY.
shared_pool(bool)trueShare L1/L2 caches across pooled connections in one process.
default_vfs(bool)envForce the process-default VFS on or off, ignoring LITEBUCKET_VFS.
write_forwarding(bool)envForce write forwarding on or off. On by default when LITEBUCKET_ADVERTISE_ADDR is set.
write_forwarding_prefix(..)LITEBUCKET_PREFIXScope write forwarding to one database prefix.
without_shutdown_flush()flush onSkip the SIGTERM flush listener.

Connect a bucket

.env
# Make LiteBucket the process-default SQLite VFS
LITEBUCKET_VFS=1
LITEBUCKET_PREFIX=prod/main

# Bucket credentials are discovered automatically from
# LITEBUCKET_*, S3_*, FILESYSTEM_* (Laravel Cloud) or AWS_* variables.

LiteBucket reads S3 settings from the first non-empty variable in each row, so Laravel Cloud Object Storage, Cloudflare R2 and AWS S3 work without renaming anything:

SettingLooked up in orderFallback
EndpointLITEBUCKET_ENDPOINT, S3_ENDPOINT, LITESTREAM_ENDPOINT, FILESYSTEM_ENDPOINT, FILESYSTEM_URL, AWS_ENDPOINT, AWS_ENDPOINT_URL_S3, AWS_ENDPOINT_URL, AWS_URLrequired
BucketLITEBUCKET_BUCKET, S3_BUCKET, LITESTREAM_BUCKET, FILESYSTEM_BUCKET, AWS_BUCKETrequired
RegionLITEBUCKET_REGION, S3_REGION, FILESYSTEM_REGION, AWS_DEFAULT_REGION, AWS_REGIONauto for R2 and Laravel Cloud, else us-east-1
Access keyLITEBUCKET_ACCESS_KEY_ID, S3_ACCESS_KEY_ID, LITESTREAM_ACCESS_KEY_ID, FILESYSTEM_ACCESS_KEY_ID, AWS_ACCESS_KEY_IDrequired
Secret keyLITEBUCKET_SECRET_ACCESS_KEY, S3_SECRET_ACCESS_KEY, LITESTREAM_SECRET_ACCESS_KEY, FILESYSTEM_SECRET_ACCESS_KEY, AWS_SECRET_ACCESS_KEYrequired
Path-styleLITEBUCKET_FORCE_PATH_STYLE, S3_FORCE_PATH_STYLE, FILESYSTEM_USE_PATH_STYLE_ENDPOINT, AWS_USE_PATH_STYLE_ENDPOINTon, except for *.amazonaws.com

Then prove your bucket supports everything LiteBucket relies on: create-only writes, compare-and-swap, and range reads.

Shell
cargo run -- sqlite:doctor

Laravel Cloud auto-setup (zero Postgres, zero disk)

Deploying on Laravel Cloud takes two variables and zero manual S3 credentials:

  1. Attach a Laravel Cloud Object Storage (R2) bucket to your environment. Laravel Cloud injects FILESYSTEM_ENDPOINT, FILESYSTEM_BUCKET, FILESYSTEM_ACCESS_KEY_ID, FILESYSTEM_SECRET_ACCESS_KEY and FILESYSTEM_REGION automatically — LiteBucket discovers all of them with zero renaming.
  2. Set two environment variables:
    Laravel Cloud Environment
    LITEBUCKET_VFS=1
    LITEBUCKET_ENCRYPTION_KEY=pass:your-strong-secret-passphrase
  3. Wire hybrid strict-central + batched-tenant storage so local dev and cargo test stay on plain local SQLite while Laravel Cloud runs 100% durable on R2:
    Real-world Laravel Cloud setup
    // src/config/database.rs — strict zero-RPO commits for central users & orgs
    let central_url = if env.get::<String>("LITEBUCKET_VFS").as_deref() == Ok("1") {
        laravel_litebucket::database_url_strict("central/main")
    } else {
        "sqlite://storage/database/central.sqlite3?mode=rwc".to_owned()
    };
    
    // src/app.rs — 1-line R2 tenant DBs when LITEBUCKET_VFS=1, local SQLite in dev/tests
    laravel::Application::configure()
        .with_litebucket()
        .with_tenancy_using(|t| {
            t.litebucket_from_env()
                .central_connection("central")
                .auto_create(false);
        })

That exact setup powers demo.litebucket.dev on Laravel Cloud — zero database service, zero persistent volume, ~1 s cold-pod hydration from R2 after container stop/start.

URL & runtime helpers

HelperWhat it returns / does
database_url("app/main")Builds a sqlx-sqlite-compatible LiteBucket URL using your configured defaults.
database_url_strict("central/main")Same, pinned to sync=strict so every commit is durable in the bucket before returning (ideal for auth/billing/central DBs).
tenanted_database_url("tenants/{tenant}/main")Per-tenant URL template with explicit prefix, write lease and tenant_key_id={tenant} (wired automatically by t.litebucket()).
flush_db().await / flush_all_open_dbs()Force an immediate flush of staged Batched commits to the bucket before responding or shutting down.
with_retry(3, || async { … })Retries transient SQLITE_BUSY / 412 contention errors in Strict multi-writer mode.
write_owner_addr() / write_owner_addr_for(prefix)Returns the private URL of the replica holding the write lease, or None when local.
02How it works

SQLite, with the bucket as its disk.

LiteBucket is a SQLite VFS that runs inside your process. SQLite asks for pages; LiteBucket serves them from memory, local NVMe, or the bucket, and ships every commit as an immutable object.

YOUR CONTAINER · ONE PROCESS Your app query! · sqlx · rusqlite litebucket-vfs SQLite VFS, in-process (C ABI) L1 · RAM LRU of 4 KB pages L2 · NVMe CRC32C + key-hash per slot COMMIT PATH Batched → RAM, upload at t = 0 by flusher Strict → upload, then COMMIT returns SIGTERM → drain + release PUT If-None-Match: * Range GET · 4 KB OBJECT STORAGE BUCKET S3 · R2 · Laravel Cloud ltx/{txid}.ltx one immutable frame per commit snapshots/c{idx}-{txid}-{uniq}.ltx compacted page chunks manifest.json current snapshot, CAS-updated write_lock.json fenced write lease YOUR CONTAINER · ONE PROCESS Your app query! · sqlx · rusqlite litebucket-vfs SQLite VFS, in-process (C ABI) L1 · RAM LRU of 4 KB pages L2 · NVMe CRC32C + key-hash per slot PUT If-None-Match: * Range GET OBJECT STORAGE BUCKET S3 · R2 · Laravel Cloud ltx/{txid}.ltx one immutable frame per commit snapshots/c{idx}-{txid}-{uniq}.ltx manifest.json write_lock.json
Reads come from RAM, then NVMe, then 4 KB Range GETs. Each commit is uploaded as a new immutable object.

Reads: lazy 4 KB pages

Opening a database doesn't download it. LiteBucket reads the manifest, then fetches only the 4 KB pages SQLite actually touches, using HTTP Range GETs and coalescing sequential runs. A multi-GB database is queryable after a couple of round trips to the bucket.

  • L1 (RAM): a bounded LRU of pages (1,024 pages by default, LITEBUCKET_CACHE_PAGES), shared across pooled connections.
  • L2 (NVMe): a 64 MB ring on local disk. Every slot carries key_hash · offset · CRC32C, so after a SIGKILL mid-write a torn or stale slot is detected and refetched from the bucket, never served.

Writes: Batched or Strict

SyncMode::Batched default

~50–200 µs per commit

COMMIT lands in an in-memory staging buffer and wakes the background flusher immediately via a Condvar. Staged pages ship as one LTX frame. Flushes also happen at 64 staged pages, on flush_db(), on connection close, and on SIGTERM.

SyncMode::Strict

RPO = 0 per commit

Every COMMIT uploads its LTX frame with If-None-Match: * before returning. Nothing acknowledged is lost, even on SIGKILL. Set LITEBUCKET_SYNC_MODE=strict.

Batched mode survives deploys, stops and hibernation because SIGTERM drains the buffer. A hard SIGKILL or power loss can drop commits that were still staged. When a single write must be durable before you respond, flush just that one:

src/http/checkout.rs
use laravel::db;

db::query!("INSERT INTO payments (order_id, cents) VALUES ({order_id}, {cents})")
    .insert()
    .await?;

// Durable in the bucket before we respond. Everything else stays sub-millisecond.
laravel_litebucket::flush_db().await?;

Fencing: no split-brain

Each commit is written to ltx/{txid}.ltx with If-None-Match: *. S3 lets exactly one writer create a given key, so two containers can never both commit transaction 42. The loser gets 412 Precondition Failed and catches up. The write lease in write_lock.json moves with If-Match ETag compare-and-swap, so during a rolling deploy the old container drains, releases the lease, and the new one takes over.

sqlite:doctor checks that your bucket really enforces both conditions before you trust it with data. With several Strict writers, wrap contended writes in with_retry:

Rust
use laravel_litebucket::with_retry;

// Strict mode with several writers: on SQLITE_BUSY / 412 it catches up and retries.
with_retry(3, || async {
    db::query!("UPDATE counters SET n = n + 1 WHERE id = 1").statement().await
})
.await?;

Bucket layout

prod/main/ ├── ltx/0000000000000001.ltx one immutable frame per commit (txid, 16 hex digits) ├── snapshots/c00000000-0000000000000040-3f9a1c2e7b4d.ltx compacted chunk ├── manifest.json current snapshot + chunk map └── write_lock.json fenced write lease + owner address

Every 32 transactions (compact_every) history is compacted into snapshot chunks. Untouched chunks are reused, and frames outside the retention window are garbage-collected.

03Multi-tenancy

One database per tenant. One bucket.

Pair LiteBucket with laravel-tenanted and every tenant gets its own SQLite database under its own prefix, with its own encryption key.

src/main.rs
use laravel_litebucket::prelude::*;
use laravel_tenanted::WithTenancy;

laravel::Application::configure()
    .with_litebucket()
    .with_tenancy_using(|t| {
        t.litebucket()
            .subdomain("example.com");
    })
    .with_routing(|routing, _| { /* ... */ })
    .run()

t.litebucket() wires the tenant database URL, per-tenant HKDF encryption, existence check, discovery, and GDPR shred hooks for tenants/{tenant}/main in one call:

MethodPrefixWhen to use
t.litebucket()tenants/{tenant}/mainDefault production multi-tenancy on S3 / R2.
t.litebucket_prefix("orgs")orgs/{tenant}/mainCustom root prefix inside your bucket.
t.litebucket_from_env()tenants/{tenant}/mainActivates LiteBucket when LITEBUCKET_VFS=1; falls back to local SQLite in dev & tests.
tenanted_database_url(…) + s3_* hooksAny templateLow-level building blocks if you need custom hook composition.

For tenant acme, the template renders to:

Rendered URL
sqlite://tenants/acme/main;prefix=tenants/acme/main;sync=batched;write_lease=1;refresh_ms=500;disk_cache_mb=64;compact_every=32;retain_txids=32;tenant_key_id=acme?mode=rwc&vfs=litebucket

Tenant IDs are validated before they reach a URL or an object key: 1–63 characters of [a-z0-9_-], starting with a letter or digit. ../evil is rejected.

Per-tenant encryption keys

Set one master key, LITEBUCKET_ENCRYPTION_KEY. Each tenant database derives its own 256-bit key with RFC 5869 HKDF-SHA256 (salt litebucket-tenant-v1, info tenant:<id>). Acme's key can't read Globex's pages, and neither can the raw master key. Rotating the master rotates every tenant, because the previous key is derived per tenant too.

To opt a deployment out of per-tenant derivation, use tenanted_database_url_with_opts(template, false).

Migrating across many tenant databases

With laravel-tenanted + LiteBucket, deploys stay fast whether you have 10 tenants or 50,000:

  • Lazy on first touch (default): Dormant tenant buckets are never downloaded on deploy. The first request for a tenant acquires a per-tenant lock, runs only pending transactional migrations, and caches the tenant as migrated. Fenced write leases + If-None-Match: * prevent two cold pods from racing.
  • Eager rollout: Run cargo run -- tenant:migrate --all (powered by s3_discover_tenants) to upgrade every discovered tenant bounded by TENANT_MAX_OPEN, or fan out jobs across a queue for 10,000+ tenants.

See Running migrations across many customer databases for expand-and-contract rolling deploy guidelines.

Offboarding and erasure

Shell
# Through laravel-tenanted (calls s3_shred_tenant)
cargo run -- tenant:delete acme --force

# Or any prefix directly
cargo run -- sqlite:shred --prefix tenants/acme/main --yes
tenanted.devDatabase-per-tenant multi-tenancy for Laravel for Rust: resolution, fail-closed guards, tenant-scoped cache, queues and files.
04Encryption & security

The bucket never sees plaintext.

Set one key and every SQLite page is encrypted inside your process with AES-256-GCM before it is uploaded.

nonce12 B · CSPRNG
ciphertext4,096 B · one SQLite page
tag16 B · GCM
AAD binds txidpgnopage_sizeis_snapshot

Each page becomes nonce ‖ ciphertext ‖ tag, 4,124 bytes for a 4 KB page. The associated data binds the page to its transaction, page number, size and snapshot flag, so a page copied to another slot or replayed into another transaction fails authentication. Every encryption draws a fresh 96-bit nonce from the OS CSPRNG, so nonces are never reused across retries, clones or re-chunking.

Because encryption is per page, lazy Range GETs still fetch and decrypt single pages. You keep cold-boot speed and the object store only ever holds ciphertext.

Keys

.env
# 32 random bytes as 64 hex characters (recommended)
#   openssl rand -hex 32
LITEBUCKET_ENCRYPTION_KEY=hex:<64 hex characters>
FormatExampleNotes
64-character hexhex:9f3c…, 0x9f3c… or bareRecommended.
32-byte base64base64:n8x…= or bareStandard or URL-safe alphabet.
Passphrasepass:correct horse battery stapleStretched with PBKDF2-HMAC-SHA256, 100,000 iterations. Fine for development; use a random key in production.

Zero-downtime key rotation

  1. Deploy both keys. Put the new key in LITEBUCKET_ENCRYPTION_KEY and the old one in LITEBUCKET_PREVIOUS_ENCRYPTION_KEY. New writes use the new key; reads fall back to the old one.
  2. Re-encrypt. Run litebucket rekey --prefix prod/main (or sqlite:rekey). It checks PRAGMA integrity_check, re-encrypts every chunk under the new key at head + 1, and commits atomically. Add --tenant-key-id acme for tenant databases.
  3. Retire the old key. Remove LITEBUCKET_PREVIOUS_ENCRYPTION_KEY.
05Point-in-time recovery

Every commit is a restore point.

History lives in the bucket as immutable frames. Query it, roll back to it, or fork it without downloading the database.

Time-travel queries

Shell
litebucket history --prefix prod/main --limit 20
litebucket sql --prefix prod/main --at=-10m "SELECT count(*) FROM orders"
litebucket sql --prefix prod/main --txid 41 "SELECT * FROM orders WHERE id = 7"

--at accepts a relative offset (-30s, -10m, -2h, -7d), RFC 3339 (2026-12-04T09:30:00Z), a UTC datetime (2026-12-04 09:30:00), or a Unix timestamp. From your app binary, sqlite:pitr does the same:

Shell
cargo run -- sqlite:pitr --at=-10m --sql "SELECT count(*) FROM orders"

Non-destructive restore

Shell
litebucket restore --prefix prod/main --at 2026-12-04T09:30:00Z

# Or take a copy to inspect locally
litebucket pull --prefix prod/main --at=-1h -o before-incident.sqlite3

Restore never rewrites history. It reads the database as it was and commits that state as the next transaction, head + 1. Everything after it is still in the bucket, so a restore can itself be undone. sqlite:restore is the Artisan equivalent.

By default, 32 transactions are retained behind the latest snapshot. For a time-based window, set LITEBUCKET_RETAIN_HOURS (for example 168 for a week).

Zero-copy clones

Shell
# Server-side CopyObject: 0 bytes downloaded
litebucket clone --from prod/main --to staging/main

# Scrub PII on the way: runs your SQL against the copy before it is written
litebucket clone --from prod/main --to dev/main --redact scrub.sql

Cloning the live head without redaction copies immutable chunks inside the bucket with CopyObject. Redacted clones, clones at an earlier --at/--txid, or clones between different encryption keys fall back to a full copy. Pass --force to overwrite an existing destination.

06Horizontal scaling

Many replicas, one writer.

Reads run locally on every replica. Writes are forwarded to whichever replica holds the lease.

Write forwarding

.env
# This replica's private address, published in write_lock.json
LITEBUCKET_ADVERTISE_ADDR=http://10.0.1.42:8080

With LITEBUCKET_ADVERTISE_ADDR set, .with_litebucket() prepends WriteForwardingMiddleware:

  • GET, HEAD and OPTIONS always run locally.
  • POST, PUT, PATCH and DELETE check, in memory, who holds the write lease. If it's another replica, the request is proxied there over your private network.
  • Forwarded requests carry X-LiteBucket-Forwarded: 1 to prevent loops. The original Host is preserved, hop-by-hop headers are stripped, and the peer's internal address never leaks to clients.

With several LiteBucket databases in one process, scope forwarding with b.write_forwarding_prefix("prod/main"). write_owner_addr() returns the current lease holder, or None when it's this replica.

Prometheus metrics

src/http/metrics.rs
async fn metrics() -> ([(laravel::http::header::HeaderName, &'static str); 1], String) {
    (
        [(laravel::http::header::CONTENT_TYPE, "text/plain; version=0.0.4; charset=utf-8")],
        laravel_litebucket::metrics_prometheus(),
    )
}

// routing.routes(|route| { route.get("/metrics", metrics); });

metrics_prometheus() renders cache hits, misses and evictions, transaction IDs and sizes for every open LiteBucket database in the process. For structured access, use all_open_dbs_stats().

07Operations

Operate it from anywhere.

The same operations ship twice: as the standalone litebucket CLI for laptops and CI, and as Artisan commands inside your app binary.

The litebucket CLI

Shell
cargo install litebucket
CommandWhat it does
litebucket doctorProves the bucket enforces If-None-Match: * and If-Match, serves Range reads, and reports round-trip times.
litebucket push [--prefix p] [--force] app.sqlite3Uploads an existing SQLite file as a LiteBucket database.
litebucket pull [--prefix p] [--txid N | --at ts] -o out.sqlite3Downloads a consistent copy, optionally from the past.
litebucket inspect [--prefix p]Size, chunks, PITR window, encryption and the active lease.
litebucket history [--prefix p] [--limit N]Restorable transactions with timestamps.
litebucket sql [--prefix p] [--txid N | --at ts] "SQL"Queries live or historical state.
litebucket restore (--txid N | --at ts) [--prefix p]Non-destructive restore at head + 1.
litebucket clone --from a --to b [--redact f.sql] [--force]Zero-copy or redacted clone.
litebucket rekey [--prefix p] [--tenant-key-id t]Re-encrypts under the new key.
litebucket shred --prefix p --yesPermanently deletes every object under a prefix.

Also included: run, init, bench, verify, compact, pitr, tail, forward, sync-local, replicate, serve-metrics and watch-compact. Run litebucket help for usage.

Artisan commands

Registered automatically by .with_litebucket(). Run them with cargo run -- <command> locally, or ./your-app <command> in production.

CommandWhat it does
sqlite:doctorVerifies bucket access, 412 fencing, If-Match CAS, Range reads and RTT.
sqlite:status [--prefix] [--lease-key]Live write-lease and LTX chain status.
sqlite:inspect [--prefix]Health, size, chunks, PITR window and encryption.
sqlite:verify [--prefix]PRAGMA integrity_check plus the full CRC64 LTX chain.
sqlite:compact [--prefix] [--retain 32]Compacts history into snapshot chunks and garbage-collects old frames.
sqlite:history [--prefix]Restorable transactions and timestamps.
sqlite:pitr (--txid N | --at ts) [--sql "…"]Read-only time-travel query.
sqlite:restore (--txid N | --at ts)Non-destructive restore at head + 1.
sqlite:rekey [--prefix]Zero-downtime key rotation.
sqlite:clone --from a --to b [--redact f.sql] [--force]Zero-copy or redacted clone.
sqlite:shred --prefix p --yesPermanently deletes a prefix.

Commands that open an encrypted database (status, verify, compact, pitr, restore, rekey, clone) also accept --tenant-key-id <tenant>, defaulting to LITEBUCKET_TENANT_KEY_ID. Relative times start with a dash, so write them as --at=-10m.

08Deployment

Deploy anywhere you can attach a bucket.

No database server to provision. Containers stay stateless; the bucket is the source of truth.

Laravel Cloud

  1. Attach an Object Storage bucket to your environment. Laravel Cloud injects its credentials and LiteBucket discovers them, no S3_* variables needed.
  2. Set LITEBUCKET_VFS=1. Optionally add LITEBUCKET_PREFIX=prod/main and an LITEBUCKET_ENCRYPTION_KEY.
  3. Deploy. On hibernation, stop or redeploy, SIGTERM drains staged commits and releases the lease. The next container cold-boots straight from the bucket. No Postgres.

Cloudflare R2 and AWS S3

.env
LITEBUCKET_VFS=1
LITEBUCKET_PREFIX=prod/main
LITEBUCKET_ENDPOINT=https://<ACCOUNT_ID>.r2.cloudflarestorage.com
LITEBUCKET_BUCKET=my-app
LITEBUCKET_ACCESS_KEY_ID=<R2_ACCESS_KEY_ID>
LITEBUCKET_SECRET_ACCESS_KEY=<R2_SECRET_ACCESS_KEY>
# Region defaults to "auto" for R2

Kamal or any VPS

On a server with a persistent disk, keep the L2 cache across restarts so a deploy starts warm:

config/deploy.yml
env:
  clear:
    LITEBUCKET_VFS: 1
    LITEBUCKET_PREFIX: prod/main
    LITEBUCKET_DISK_CACHE_PERSISTENT: 1
    LITEBUCKET_DISK_CACHE_DIR: /storage/litebucket-cache
  secret:
    - LITEBUCKET_ENDPOINT
    - LITEBUCKET_BUCKET
    - LITEBUCKET_ACCESS_KEY_ID
    - LITEBUCKET_SECRET_ACCESS_KEY
    - LITEBUCKET_ENCRYPTION_KEY
volumes:
  - /var/lib/my-app/storage:/storage

Whatever the platform, run litebucket doctor against the bucket once before the first deploy.

09Reference

Environment variables.

Everything has a production default. URL parameters override env vars, and env vars override builder defaults.

VariableDefaultPurpose
LITEBUCKET_VFSoffMake litebucket the process-default SQLite VFS.
LITEBUCKET_PREFIX—Database prefix inside the bucket. CLI and Artisan default to app/db.
LITEBUCKET_SYNC_MODEbatchedbatched or strict.
LITEBUCKET_WRITE_LEASE1Fenced single-writer lease.
LITEBUCKET_FLUSH_INTERVAL_MS100Fallback flush timer in Batched mode.
LITEBUCKET_FLUSH_MAX_PAGES64Flush synchronously once this many pages are staged.
LITEBUCKET_CACHE_PAGES1024L1 RAM cache size in 4 KB pages.
LITEBUCKET_DISK_CACHE_MB64L2 NVMe cache budget; 0 disables.
LITEBUCKET_DISK_CACHE_DIROS temp dirWhere the L2 cache lives.
LITEBUCKET_DISK_CACHE_PERSISTENToffKeep the L2 cache across restarts.
LITEBUCKET_REFRESH_MS500Background catch-up interval.
LITEBUCKET_COMPACT_EVERY32Auto-compact every N transactions.
LITEBUCKET_RETAIN_TXIDS32Transactions kept for PITR during GC.
LITEBUCKET_RETAIN_HOURSoffTime-based PITR window.
LITEBUCKET_ENCRYPTION_KEYoffAES-256-GCM key: hex, base64 or pass:.
LITEBUCKET_PREVIOUS_ENCRYPTION_KEY—Old key, read-only fallback during rotation.
LITEBUCKET_TENANT_KEY_ID—Default tenant for CLI and Artisan key derivation.
LITEBUCKET_ADVERTISE_ADDR—This replica's private URL; enables write forwarding.

Bucket credentials are covered in Connect a bucket. The full API is on docs.rs.