Manual deployment
This page sets up a Civility server on one Linux machine. systemd keeps the server running, and Caddy puts HTTPS in front of it. The database is a SQLite file and uploaded files go to a local directory.
You need a Linux server you can sudo on, and a domain name that points at it.
The commands are for Fedora. Where another distribution differs, the step says so. The examples use these paths:
| Path | What it holds |
|---|---|
/var/lib/civility |
Home directory of the civility user. |
/var/lib/civility/.deno |
Deno and the civ command. |
/var/lib/civility/civility.db |
The database. |
/var/lib/civility/.data/blobs |
Uploaded files. |
/etc/civility/env |
Secrets. |
/etc/systemd/system/civility.service |
The systemd unit. |
1. Create a service user
Install the tools the Deno installer needs.
sudo dnf upgrade -y
sudo dnf install -y curl unzip
On Debian or Ubuntu, use sudo apt update && sudo apt install -y curl unzip.
Create a user that cannot log in, with its home at /var/lib/civility.
sudo useradd -r -s /sbin/nologin -d /var/lib/civility civility
sudo mkdir -p /var/lib/civility
sudo chown civility:civility /var/lib/civility
2. Install Deno
Install Deno into the civility user's home.
sudo -u civility bash -c 'curl -fsSL https://deno.land/install.sh | DENO_INSTALL=/var/lib/civility/.deno sh'
Check that it runs.
sudo -u civility /var/lib/civility/.deno/bin/deno --version
3. Install the CLI
sudo -u civility /var/lib/civility/.deno/bin/deno install \
jsr:@civility/cli -Afg --unstable-cron --name=civ \
--root /var/lib/civility/.deno
This creates /var/lib/civility/.deno/bin/civ. To install a specific version, write jsr:@civility/cli@<version>.
The --unstable-cron flag lets the server run its scheduled jobs (pruning, blob cleanup, metering). Without it the jobs do not run, and you have to run civ api gc blobs --once yourself from cron or a systemd timer.
civ is a small script that runs deno, so deno must be on the PATH whenever you run it. Otherwise you get exec: deno: not found.
4. Create the secrets file
Generate the auth secret and, if you want one, an admin token. Copy the output of each command.
sudo -u civility env PATH=/var/lib/civility/.deno/bin:$PATH civ api gen-secret sudo -u civility env PATH=/var/lib/civility/.deno/bin:$PATH civ admin tokenCreate the file so that only the
civilityuser can read it.sudo mkdir -p /etc/civility sudo touch /etc/civility/env sudo chmod 600 /etc/civility/env sudo chown civility:civility /etc/civility/envEdit
/etc/civility/env. Write plainKEY=valuelines. Do not useexport, because systemd does not accept it.# Required. Signs sessions and encrypts credentials saved in /admin. CIVILITY_AUTH_SECRET=replace_with_your_secret # Accounts with these emails can open /admin after signing in. CIVILITY_ADMIN_EMAILS=you@example.org # Optional. Token for scripts that call /admin. CIVILITY_ADMIN_TOKEN=replace_with_your_token # Optional. Directory for uploaded files until you save a storage # setting in /admin/storage. Default: ./.data/blobs # CIVILITY_BLOB_PATH=/var/lib/civility/.data/blobs
The environment variable table explains each one. Keep a copy of CIVILITY_AUTH_SECRET somewhere off this server.
5. Test the server by hand
Start the server once as the civility user to check that it runs.
sudo -u civility bash -c '
export HOME=/var/lib/civility
export PATH=/var/lib/civility/.deno/bin:$PATH
set -a; source /etc/civility/env; set +a
cd /var/lib/civility
civ api start \
--hostname 127.0.0.1 \
--port 3848 \
--db-path /var/lib/civility/civility.db
'
The server prints its version, port and admin panel address. If CIVILITY_AUTH_SECRET is missing, it prints an error and exits. Press Ctrl+C to stop it.
Because the command passes flags, the server asks no questions and writes no config file.
6. Create the systemd service
Create /etc/systemd/system/civility.service.
[Unit]
Description=Civility sync server
Documentation=https://tangled.org/bpev.me/civility
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
User=civility
Group=civility
EnvironmentFile=/etc/civility/env
Environment=PATH=/var/lib/civility/.deno/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Environment=DENO_DIR=/var/lib/civility/.cache/deno
# Relative paths, such as the default blob directory, start here.
WorkingDirectory=/var/lib/civility
ExecStart=/var/lib/civility/.deno/bin/civ api start \
--db-path /var/lib/civility/civility.db \
--hostname 127.0.0.1 \
--port 3848
Restart=on-failure
RestartSec=5s
NoNewPrivileges=yes
PrivateTmp=yes
ProtectSystem=strict
ReadWritePaths=/var/lib/civility
[Install]
WantedBy=multi-user.target
The server listens on 127.0.0.1, so only Caddy on the same machine can reach it.
Enable and start the service.
sudo systemctl daemon-reload
sudo systemctl enable --now civility
sudo systemctl status civility
Read the logs with:
sudo journalctl -u civility -f
If status shows status=217/USER, the civility user does not exist. Go back to step 1.
7. Install Caddy
sudo dnf install -y caddy
On Arch, use sudo pacman -S caddy. On Debian or Ubuntu, add Caddy's package repository first. See Caddy's install page.
8. Configure Caddy
Create /etc/caddy/Caddyfile. Replace your-domain.com with your domain and 203.0.113.10 with the IP address you manage the server from.
your-domain.com {
# Hide the admin panel from every address except the ones listed.
@admin_blocked {
path /admin /admin/*
not remote_ip 203.0.113.10
}
respond @admin_blocked "Not Found" 404
reverse_proxy 127.0.0.1:3848
}
To allow more addresses or a subnet, list them with spaces between them.
not remote_ip 203.0.113.10 198.51.100.0/24 10.8.0.0/16
The address check is an extra layer. The server still requires an admin sign-in or the admin token. If you do not want the address check, remove the @admin_blocked block and the respond line.
Check the file and start Caddy.
sudo caddy validate --config /etc/caddy/Caddyfile
sudo systemctl enable --now caddy
sudo systemctl reload caddy
Caddy gets a Let's Encrypt certificate for the domain by itself.
9. Open the firewall
Open ports 80 and 443. Caddy uses port 80 to get certificates. Port 3848 stays closed, because the server only listens on 127.0.0.1.
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
On Debian or Ubuntu with ufw, use sudo ufw allow http && sudo ufw allow https. If your hosting provider has its own firewall, open the same two ports there.
10. Check that it works
# The server answers and reports its version.
curl https://your-domain.com/health
# From an address that is not on the Caddy list, the panel returns 404.
curl -i https://your-domain.com/admin/
# From your listed address, the admin token works.
curl -H "Authorization: Bearer your_admin_token" https://your-domain.com/admin/users
Then open https://your-domain.com/signup in a browser, create an account with an email from CIVILITY_ADMIN_EMAILS, and open https://your-domain.com/admin/.
Next, set up email in /admin/email. Until you do, the server prints messages such as password reset links to its log and does not send them. See the admin panel page.
Upgrade
Back up the database.
Read the schema changes section of the runbook.
Install the new version and restart.
sudo -u civility /var/lib/civility/.deno/bin/deno install \ jsr:@civility/cli@<version> -Afg --unstable-cron --name=civ \ --root /var/lib/civility/.deno sudo systemctl restart civilityCheck that
curl https://your-domain.com/healthreports the new version.
To roll back, install the previous version the same way and restart.
If the install fails with a permission error, some files under /var/lib/civility belong to root. Fix that with sudo chown -R civility:civility /var/lib/civility.
Back up
Back up three things:
- The database,
/var/lib/civility/civility.db. - The uploaded files,
/var/lib/civility/.data/blobs. If you saved a different directory in/admin/storage, back up that one. - The secrets file,
/etc/civility/env. A restored database cannot read the credentials saved in the admin panel without itsCIVILITY_AUTH_SECRET.
With the server stopped
sudo systemctl stop civility
sudo -u civility bash -c '
cd /var/lib/civility
tar -czf /var/lib/civility/backup-$(date +%Y%m%d).tar.gz civility.db* .data/blobs
'
sudo systemctl start civility
civility.db* includes the -wal and -shm files that SQLite keeps next to the database. If nothing has been uploaded yet, .data/blobs may not exist; leave it out of the command. Copy the archive to another machine.
With the server running
The sqlite3 command (sudo dnf install -y sqlite) can copy the database while the server writes to it.
sudo -u civility sqlite3 /var/lib/civility/civility.db ".backup /var/lib/civility/civility-backup.db"
Then copy civility-backup.db and the blob directory to another machine.
Files in a bucket
If uploaded files are in an S3 bucket, turn on object versioning at your provider, so that a deleted file can be recovered. Add a lifecycle rule to remove old versions after a while. With the AWS CLI:
aws s3api put-bucket-lifecycle-configuration \
--bucket civility-blobs \
--lifecycle-configuration '{
"Rules": [{
"ID": "expire-noncurrent",
"Status": "Enabled",
"Filter": {},
"NoncurrentVersionExpiration": { "NoncurrentDays": 30 }
}]
}'
Restore
Test a restore a few times a year, so that you know the backups work.
Unpack the archive into an empty directory.
sudo mkdir -p /var/lib/civility/restore sudo chown civility:civility /var/lib/civility/restore sudo -u civility tar -xzf /var/lib/civility/backup-20260101.tar.gz -C /var/lib/civility/restoreStart a second server on another port that reads the restored files.
sudo -u civility bash -c ' export HOME=/var/lib/civility export PATH=/var/lib/civility/.deno/bin:$PATH set -a; source /etc/civility/env; set +a export CIVILITY_BLOB_PATH=/var/lib/civility/restore/.data/blobs cd /var/lib/civility civ api start --port 3849 --hostname 127.0.0.1 \ --db-path /var/lib/civility/restore/civility.db 'In another shell, run
curl http://127.0.0.1:3849/health. Then sign in as a known user and check that their data and files are there.To put the restored copy into service, stop both servers, move the restored
civility.db*and.data/blobsto their normal paths, and runsudo systemctl start civility.
If a storage setting is saved in /admin/storage, the restored server uses that setting and ignores CIVILITY_BLOB_PATH. Check the page before you trust a file download from the test server.
Move uploaded files to a bucket
You change blob storage in the admin panel. The server does not need a restart. Changing the setting does not move existing files, so copy them first.
Create the bucket and upload the files from
/var/lib/civility/.data/blobsinto it under their bucket names. A plain copy does not work: see Move to a different place.Open
/admin/storage, choose S3-compatible, fill in the endpoint, bucket and keys, and save.Open an app and check that a file uploaded before the change still loads.
Delete the local copy once you are sure the bucket holds every file.
sudo -u civility bash -c ' export HOME=/var/lib/civility export PATH=/var/lib/civility/.deno/bin:$PATH set -a; source /etc/civility/env; set +a cd /var/lib/civility civ api gc blobs --once --db-path /var/lib/civility/civility.db '
See Blob storage for details.
Disk encryption
The server does not encrypt the database or the uploaded files on disk. It only encrypts the credentials you save in the admin panel, using CIVILITY_AUTH_SECRET. User data is stored as the apps send it.
- For the local disk, use full-disk encryption such as LUKS, or an encrypted volume from your hosting provider.
- For a bucket, check that server-side encryption is on in the bucket settings. Most providers turn it on by default.
Appendix: S3 provider endpoint reference
In /admin/storage, the Endpoint field takes a host name without https://, port or path. A port and plain HTTP have their own fields.
| Provider | Endpoint | Notes |
|---|---|---|
| AWS S3 | s3.amazonaws.com |
Or a regional host: s3.us-east-1.amazonaws.com. |
| Cloudflare R2 | <account_id>.r2.cloudflarestorage.com |
Set Region to auto. |
| Hetzner Object Storage | <region>.your-objectstorage.com |
Regions: fsn1, nbg1, hel1. |
| Backblaze B2 | s3.<region>.backblazeb2.com |
For example s3.us-west-004.backblazeb2.com. |
| MinIO | Your MinIO host, such as minio.example.com |
Set Region to us-east-1, and Port if not 443. |
Check the endpoint against your provider's own documentation.