Self-hosting
The server is one binary and one SQLite file. It needs no other service. A small VPS is enough.
Build
You need Rust stable and a C compiler (SQLite is bundled).
cargo build --release -p koko-server
The binary is target/release/koko-server.
There is also an alternative server written in TypeScript for Bun, in koko-server-bun. It speaks the same protocol and uses the same database file, but it has no Web Push and the Rust server is the canonical one. Unless you want TypeScript, use the Rust binary.
Run
KOKO_BIND=127.0.0.1:8080 KOKO_DB=/var/lib/koko/koko.db ./koko-server
Check it: curl http://127.0.0.1:8080/healthz prints ok.
Put TLS in front
Version 1 has no end-to-end encryption and the server speaks plain HTTP and WebSocket. Put a reverse proxy with TLS in front of it, or passwords and tokens cross the network in the clear. With Caddy this is the whole file:
chat.example.org {
reverse_proxy 127.0.0.1:8080
}
Caddy upgrades WebSocket connections on its own. With nginx, pass the upgrade headers:
location / {
proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Forwarded-For $remote_addr;
proxy_read_timeout 120s;
}
Then start the server with KOKO_TRUST_PROXY=1 so rate limits use the real client address. Only set it when the server is reachable through your own proxy and nothing else.
Run as a service
[Unit]
Description=Koko server
After=network.target
[Service]
ExecStart=/usr/local/bin/koko-server
Environment=KOKO_BIND=127.0.0.1:8080
Environment=KOKO_DB=/var/lib/koko/koko.db
Environment=KOKO_TRUST_PROXY=1
User=koko
StateDirectory=koko
Restart=on-failure
[Install]
WantedBy=multi-user.target
Back up
The database runs in WAL mode. Use SQLite's online backup so the copy is consistent:
sqlite3 /var/lib/koko/koko.db ".backup /backups/koko.db"
Web client on another origin
If you host the web client on a different origin than the server, tell the server which origin may call it with KOKO_CORS_ORIGIN. See Configuration.