🪶
Hosting

Can you use SQLite in production?

15.11.2026
← All articles

Many developers treat SQLite as a toy database for tests. In reality it is one of the most widely deployed database engines, running inside phones, browsers and countless programs, and recent Laravel versions create new projects with SQLite by default. The real question is not whether SQLite is good, but whether it is enough for your project.

How SQLite differs from MySQL

MySQL and PostgreSQL are separate server processes that manage users, permissions and concurrent connections. SQLite has no server: the whole database is one file that your app reads and writes through a library. Setup is trivial and reads are very fast. The key limitation is writing: only one writer at a time. Readers can run in parallel, but a second writer waits, and if the wait times out the app gets database is locked.

Where SQLite is plenty

Take a course enrolment site for a training centre in Andijan: a few hundred visitors a day, a few dozen applications and occasional schedule updates. That is less than one write per second, each taking milliseconds, and SQLite will run it for years. It also fits read-heavy blogs and catalogues, small internal tools, Telegram bots and small APIs on a single server.

Where it becomes a problem

Many simultaneous writers, such as a store taking dozens of orders per second during a sale, turn the single-writer rule into a bottleneck. SQLite also does not fit apps spread across several servers, and sharing the file over network filesystems like NFS is discouraged because file locking is unreliable there. There are no users or permissions either: any process that can read the file can read everything. For those needs, use MySQL or PostgreSQL.

Protecting the database file

The most dangerous mistake is leaving app.db inside public_html, where anyone can download it with a browser. Keep it outside the web root:

/home/user/misol.uz/
├── data/
│   └── app.db          # database lives here, not web-accessible
└── public_html/
    └── index.php

If a script insists on the public folder, at least block web access on Apache hosting:

# public_html/.htaccess
<FilesMatch "\.(db|sqlite|sqlite3)$">
    Require all denied
</FilesMatch>

SQLite creates journal files next to the database (-wal, -shm or -journal), so the directory itself must be writable by PHP, otherwise you get attempt to write a readonly database.

WAL mode and busy timeout

WAL mode lets readers keep working while a write is in progress, and busy_timeout makes a blocked query wait instead of failing at once. Foreign key checks are off by default and must be enabled per connection.

<?php
$pdo = new PDO('sqlite:' . __DIR__ . '/../data/app.db');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->exec('PRAGMA journal_mode = WAL');
$pdo->exec('PRAGMA busy_timeout = 5000');
$pdo->exec('PRAGMA synchronous = NORMAL');
$pdo->exec('PRAGMA foreign_keys = ON');

With WAL, synchronous = NORMAL keeps the database consistent if the app crashes, but a sudden power loss may drop the latest transactions; keep FULL if every write matters. In Laravel use an absolute path:

# .env (Laravel)
DB_CONNECTION=sqlite
DB_DATABASE=/home/user/misol.uz/data/app.db

Keep transactions short and never call external APIs inside them.

Backing up correctly

Copying a live database with cp can produce an incomplete backup, especially with pending WAL changes. Use SQLite's own tools and verify the result:

# safe copy of a live database
sqlite3 /home/user/misol.uz/data/app.db ".backup '/home/user/backup/app.db'"

# or (SQLite 3.27+)
sqlite3 /home/user/misol.uz/data/app.db "VACUUM INTO '/home/user/backup/app-copy.db'"

# integrity check, expected: ok
sqlite3 /home/user/backup/app.db "PRAGMA integrity_check;"
0 3 * * * sqlite3 /home/user/misol.uz/data/app.db ".backup '/home/user/backup/app-$(date +\%F).db'"

When to move on

Regular database is locked errors, a database of several gigabytes with slow backups, or plans for a second app server all mean it is time to migrate. In Laravel or Django, migrations are database-agnostic, so switching is mostly a config change plus a data move. On sayt.uz hosting you can create a MySQL database from the control panel, so starting small and upgrading later is a practical path.

Related articles

🤖 Telegram bot "Conflict: terminated by other getUpdates" error: cause and fix 🔁 Migrating a WordPress Site: Replacing URLs Without Breaking Serialized Data 📊 Grafana and Prometheus: server monitoring basics 📬 Migrating Mailboxes with imapsync Without Losing a Single Email
🌐 Language
🇺🇿 O'zbek 🇺🇿 Ўзбек 🇷🇺 Русский 🇬🇧 English ✓