Lapis Docs

Running a site

Deploying

Lapis is a plain PHP application. By default its content is an SQLite file and the uploaded files, both in the storage/ folder. There is no Node build step and no database server to run, so most PHP hosts can run it. MySQL and PostgreSQL work too, see the database. This guide walks you through the requirements, the first install, the web server, updates and backups.

What the host needs

  • PHP 8.5 or newer, CLI too (over SSH or the host's console).
  • Extensions: pdo_sqlite (or pdo_mysql, pdo_pgsql for another database), dom, intl. Recommended: gd with WebP (image variants, or imagick with IMAGE_DRIVER, see Images), exif (rotating phone photos), zlib and phar (backups).
  • HTTPS. The editor cannot save without it: browsers only send the Sec-Fetch-Site header on secure connections, and the CSRF protection requires it.
  • A persistent file system. The database and the uploads are files, see the warning below.
  • Cron (daily backup, scheduled tasks).
  • memory_limit = 256M is recommended. A page request takes 2 to 3 MB with OPcache, but image processing grows with the image's megapixels: 12 MP → ~70 MB, 24 MP → ~115 MB, 48 MP → ~210 MB. The default 128M is enough for about 25 MP, 256M for about 57 MP. Lapis refuses larger images on upload with a clear message, and ./lapis doctor tells the limit on this server.

./lapis doctor checks all of this on the server.

First install

git clone … site && cd site          # or upload the files
composer install --no-dev --optimize-autoloader
./lapis setup                        # .env with SIGNING_KEY, storage folders, vendor assets, first editor

The production settings in .env:

ENVIRONMENT=production
SIGNING_KEY=…                        # created by setup; do not change it (everyone would be signed out)
BASE_URI=https://example.com

# optional: switch Lapis's caches off (on in production by default)
# CACHE_LAPIS_PAGES_ENABLED=false
# CACHE_LAPIS_LOADERS_ENABLED=false

# optional: when set, the login page shows "Forgot your password?"
MAIL_SMTP_HOST=smtp.example.com
MAIL_SMTP_PORT=587
MAIL_SMTP_USERNAME=…
MAIL_SMTP_PASSWORD=…
[email protected]
MAIL_SENDER_NAME="Example"

Then:

./lapis deploy        # vendor assets, compiled assets, public/uploads link, cache clear, checks

When a step fails (for example a plugin's build), deploy stops there and exits with an error. The assets already in public/assets stay as they were.

Finally, add the cron line (crontab -e). It runs every minute, and the daily backup is made once a day:

* * * * * cd /path/to/site && php lapis schedule:run

The database

SQLite is the default: storage/content/lapis.sqlite, nothing to set up. MySQL 8.0.13 or newer and PostgreSQL 14 or newer work too, with these in .env:

DB_CONNECTION=mysql                  # sqlite (the default), mysql or pgsql
DB_HOST=127.0.0.1
DB_PORT=3306                         # 5432 for PostgreSQL
DB_DATABASE=lapis
DB_USERNAME=lapis
DB_PASSWORD=…

The database must exist, Lapis creates the tables in it on boot. On MySQL, create it with utf8mb4 (CREATE DATABASE lapis CHARACTER SET utf8mb4).

To move a site to another database, back it up (./lapis backup), set DB_CONNECTION and the rest, then restore the backup (./lapis backup:restore <name>). A backup from any of the three restores into any of them.

Web server

The document root is the public/ folder. Everything else (storage/, .env, vendor/) stays outside it.

nginx

server {
    listen 443 ssl http2;
    server_name example.com;
    root /var/www/site/public;
    index index.php;

    # Compiled assets and image variants: their names contain a content hash.
    location /assets/ { expires max; add_header Cache-Control "public, immutable"; try_files $uri /index.php?$query_string; }
    # Uploads: files only, never run as PHP (^~ wins over the \.php$ location below),
    # and an SVG opened directly cannot run script or load anything.
    location ^~ /uploads/ {
        expires 30d;
        add_header X-Content-Type-Options nosniff always;
        location ~* \.svg$ {
            add_header X-Content-Type-Options nosniff always;
            add_header Content-Security-Policy "default-src 'none'; style-src 'unsafe-inline'; sandbox" always;
        }
        location ~* \.(php|phtml|phar)$ { return 404; }
        try_files $uri /index.php?$query_string;
    }

    location / { try_files $uri /index.php?$query_string; }

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_pass unix:/run/php/php8.5-fpm.sock;
    }

    location ~ /\. { deny all; }
    client_max_body_size 20m;   # at least maxUploadMb of lapis.config.php
}

Apache (public/.htaccess)

Options -Indexes
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

# Uploads are files, never scripts.
RewriteRule ^uploads/.*\.(php|phtml|phar)$ - [F,L,NC]

<IfModule mod_headers.c>
    <FilesMatch "\.(css|js|woff2|webp|avif|jpg|png|svg)$">
        Header set Cache-Control "public, max-age=31536000, immutable"
    </FilesMatch>
    # An SVG opened directly cannot run script or load anything.
    <FilesMatch "\.svg$">
        Header set Content-Security-Policy "default-src 'none'; style-src 'unsafe-inline'; sandbox"
        Header set X-Content-Type-Options "nosniff"
    </FilesMatch>
</IfModule>

If the host runs PHP for every .php file (most shared hosts), also turn it off inside the uploads folder, e.g. in the virtual host: <Directory /var/www/site/storage/uploads> php_admin_flag engine off </Directory> (with PHP-FPM: <FilesMatch \.php$> SetHandler none </FilesMatch>).

Security checklist

  • BASE_URI starts with https://: only then does the session cookie get Secure (./lapis doctor fails without it in production). Redirect plain HTTP to HTTPS in the web server.
  • Uploads are never executed and SVGs get the CSP above. Lapis already cleans every SVG on upload (an allow-list of drawing elements), and the header is a second line of defense. After a Lapis update with a stricter cleaner, ./lapis media:clean-svg cleans the existing ones again.
  • importmap.php holds a hash (integrity) for every downloaded package. importmap:install refuses a download that differs, and doctor reports a vendor file changed on disk.
  • Only restore backups you made: backup:restore refuses archives with anything besides the database and uploads, and skips uploads with other extensions, but the database itself (accounts included) is taken as it is.

On shared hosting where the domain's root cannot point at public/, ask the provider, or put the project one level up and the contents of public/ into the domain's root (adjust the paths in public/index.php).

Updating

git pull
composer install --no-dev --optimize-autoloader
./lapis deploy

The database schema updates itself on every boot. Before an update a manual backup is a good idea: ./lapis backup --name=before-update.

Backups

  • ./lapis backup saves into a single .tar.gz under storage/backups: a consistent database snapshot (also while the site is running) and the uploads (--uploads=false backs up the database only). The snapshot is database.sqlite on SQLite and database.json (every table's rows) on MySQL and PostgreSQL. Cron makes one daily (backup:daily) and keeps the latest 14 (backupKeep). Named backups (--name=…) are never pruned automatically.
  • Restore: ./lapis backup:list, then ./lapis backup:restore <name>.

When something does not work

Symptom Cause Fix
The editor gets 403 when saving no HTTPS, or a proxy strips the Sec-Fetch-* headers HTTPS. Behind a proxy, pass the headers on
Error 500 an error in the code or on the server the details are in storage/logs/lapis-*.log
Images show in their original size no image driver install ext-gd (or ext-imagick), then ./lapis media:regenerate
Phone photos appear rotated no exif ext-exif, then upload or replace the images again
"The image is too large for this server" on upload memory_limit is too low for the image's megapixels memory_limit = 256M (php.ini or the host's panel), or a smaller image
No daily backup is made cron is not running ./lapis doctor shows it, the cron line is above
Forgotten password no e-mail configured, so there is no reset link on the server: ./lapis user:password