Skip to the content
Documentation
Help Start
Reading in:
  • German: 9,059 of 9,059 pages
About the help in other languages
All help pages

SQLite files, ownership and permissions

The four files of an Exponential SQLite database, which process must be able to write which file, how to set up one common group with the setgid bit and a umask of 0002 so that PHP-FPM, Velocity, cronjobs and console…

Download as PDF

Address: https://doc.exponential.earth/exphelp/viewer/help/database-administrators/sqlite-files-ownership-and-permissions.md

On this page

SQLite files, ownership and permissions

This page is for database administrators and system administrators who set up or repair the files of an Exponential SQLite database. With SQLite the file system is the access control: the right owner, group and mode are what grants and roles are on a server database. This page answers: which files exist, who must write them, how to set them up once so that every process keeps working, and how to check that the database cannot be downloaded. Source: Files, ownership and mixed users.

Warning

.htaccess slows down every request. When .htaccess files are enabled (AllowOverride anything but None), let alone used, Apache looks for them and reads and evaluates them on every request, in every directory of the path, and page loading times go up drastically (measured). The only real fix is to switch the feature off for the virtual host: AllowOverride None in the HTTPS virtual host, and the rules in the virtual host's own configuration as mod_rewrite rules. That is far faster in production speed tests and well worth the time it takes to optimize a production configuration. Switch over right away: copy the rules of the example HTTPS virtual host into your virtual host (with the static cache, also staticcache_offload.conf), set AllowOverride None, run apachectl configtest, reload Apache and test the site. The same rules for other servers: nginx, LiteSpeed, Caddy, IIS, Velocity (built in); where virtual host rules go in a control panel: Plesk, cPanel, DirectAdmin, ISPConfig. On LiteSpeed or OpenLiteSpeed, the server's own page cache can also answer anonymous visitors and crawlers without PHP: Page caching with LiteSpeed and OpenLiteSpeed.

Contents

  1. The four files
  2. Who uses the database
  3. Set it up once
  4. Check after a day
  5. What not to do
  6. Never serve the database over HTTP
  7. Checklist

The four files

FileWhat it isWho needs to write it
exponential.dbthe databaseevery process that writes
exponential.db-walthe write-ahead logevery process that writes
exponential.db-shmthe shared-memory index of the WALevery process, readers too
exponential.db.writer-lockthe driver's write queueany process (read-only is enough for flock())
exponential.db.writer-queuetells a writer that others are waitingany process (read-only is enough for flock())

SQLite creates and removes -wal and -shm itself, so the directory must be writable by every process as well. The driver creates var/storage/sqlite3/ with mode 0775, but it does not set the mode or owner of the files: they get the owner and umask of whichever process created them first.

Who uses the database

On a typical server three kinds of process open it:

  • the web server's PHP (PHP-FPM or mod_php), as the site user;
  • Velocity workers;
  • cronjobs and console commands, often another user, sometimes root.

If one of them creates -shm with mode 0644, the others fail with "attempt to write a readonly database".

Set it up once

# one group that every process runs with (the web server's group is usual)
chgrp -R <web group> var/storage/sqlite3
# the setgid bit: files created in the directory inherit its group
chmod 2775 var/storage/sqlite3
chmod 664 var/storage/sqlite3/*

Then give every process a umask of 0002, so new files are group-writable:

  • in a systemd unit: UMask=0002;
  • at the top of a cron line: umask 002; cd /path/to/installation && php runcronjobs.php ...;
  • in the PHP-FPM pool and Velocity's service, through their service manager.

Chapter 8 covers the users the servers run as; Writable directories and permissions the same for hosting companies.

Check after a day

ls -l var/storage/sqlite3/

Every file should be group-writable and carry the common group (owner, group and sizes are yours):

-rw-rw-r-- 1 example www-data 187678720 Oct  5 10:14 exponential.db
-rw-rw-r-- 1 example www-data     32768 Oct  5 10:20 exponential.db-shm
-rw-rw-r-- 1 example www-data   4124152 Oct  5 10:20 exponential.db-wal
-rw-rw-r-- 1 example www-data         0 Oct  5 09:58 exponential.db.writer-lock

What not to do

  • Do not run bin/modfix.sh (bin:modfix) to fix this. It makes var/storage and other directories world-writable (mode 777, files 666), and the script itself warns that this is not secure. Fix the group and mode as above.
  • Do not delete -wal or -shm while any process has the database open.
  • Do not put the database on a network file system shared by several machines: WAL needs shared memory on one host.
  • Do not copy a busy database file as a backup; use .backup or VACUUM INTO (Backups per engine).

Never serve the database over HTTP

The database lives below var/storage, which the shipped .htaccess sends to index.php and which Velocity's list of static files leaves out. If the web server is configured by hand, check it on your own host; anything but 200 is right:

curl -sI https://www.example.com/var/storage/sqlite3/exponential.db | head -1

A database kept at an absolute path outside the document root (Database=/srv/exponential/data/site.db) cannot be served at all; the same ownership rules apply to that directory.

Checklist

  • To do: One common group for every process; directory 2775; files 664.
  • To do: Every process (PHP-FPM, Velocity, cron, console) runs with umask 0002.
  • To do: No file in var/storage/sqlite3/ is owned by a user the others cannot write for.
  • To do: curl -sI on the database address does not return 200.
  • To do: Backups of the file are readable only by administrators.

Become an Exponential Partner

Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.

Something wrong on this page? Report an error

Documentation license

This documentation is free documentation, licensed under the GNU Free Documentation License 1.3 or later.

Exponential Copyright © 1998-2026 Exponential Foundation and 7x