Guides

Install on Ubuntu

Prepare an Ubuntu Virtual Private Server (VPS), install Charter, and run it under systemd.

You may install Charter on an Ubuntu Virtual Private Server (VPS) and supervise it with systemd. By the end of this page the binary listens on port 3000 and restarts on boot.

What you need#

  • An Ubuntu server (22.04 LTS or newer) that can accept traffic from the public internet
  • Secure Shell (SSH) access with a key, not a password
  • A domain name is optional here. Add one when you put Charter behind Cloudflare; see Mutual TLS with Cloudflare

This guide sticks to Ubuntu. For a first-time host checklist (SSH keys, a non-root admin user, Uncomplicated Firewall), see DigitalOcean's Initial Server Setup collection and pick the Ubuntu guide. For the firewall, follow UFW on Ubuntu. Broader server docs live in the Ubuntu Server documentation.

Prepare the host#

Before you install Charter:

  • Create a dedicated charter system user with no login shell. That user should own the Charter process and its files.
  • Prefer SSH keys over password login. Keep port 22 open for administration only.
  • Optionally turn on unattended security updates for the host operating system.
  • Create /etc/charter for an environment file and any later Transport Layer Security (TLS) material. Private keys should be mode 600 and owned by charter.
sudo useradd --system --home /var/lib/charter --shell /usr/sbin/nologin charter
sudo install -d -o charter -g charter -m 750 /var/lib/charter
sudo install -d -o charter -g charter -m 750 /etc/charter

Addresses and firewall rules for this guide:

  • Application Programming Interface (API) listener: 0.0.0.0:3000, plain Hypertext Transfer Protocol (HTTP)
  • Host firewall: allow Transmission Control Protocol (TCP) 22 for SSH and 3000 for the API. Do not publish other ports you do not need.
Info

Port 3000 avoids a privileged bind while you bring the host up. When Charter itself handles TLS, for example in Mutual TLS with Cloudflare, move the API listener to port 443.

Install Charter#

Use any channel on the Install page. On Ubuntu, the install script or the ghcr.io/snaapi/charter container image are the usual choices. For Docker Compose instead of systemd, see Deploy with Docker. For a host managed with systemd, put the binary where the service can run it, for example /usr/local/bin/charter.

Confirm the install:

charter --version

You may import your API with charter import config --path charter.toml --apply. Production runs charter serve. charter dev is the local command from the Quickstart.

Supervise with systemd#

systemd is the process manager on Ubuntu Server. It starts Charter on boot and restarts it if it exits. See systemd unit file basics.

Create /etc/charter/charter.env with mode 600, owned by charter. Put at least DATABASE_URL there, plus any other runtime settings from Environment variables. The database role behind that URL needs the privileges in Requirements.

/etc/systemd/system/charter.service:

[Unit]
Description=Charter API
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
User=charter
Group=charter
WorkingDirectory=/var/lib/charter
EnvironmentFile=/etc/charter/charter.env
ExecStart=/usr/local/bin/charter serve \
  --host 0.0.0.0 \
  --port 3000
Restart=on-failure
RestartSec=5
NoNewPrivileges=true

[Install]
WantedBy=multi-user.target

Enable and start the service:

sudo systemctl daemon-reload
sudo systemctl enable --now charter.service
sudo systemctl status charter.service

Check it#

From the server:

curl -sS http://127.0.0.1:3000/healthz

From another machine that can reach the host, use the same path on port 3000. You should get a successful health response once the service is up and the firewall allows the port.

Put Cloudflare in front#

When the hostname is proxied through Cloudflare and you want the origin to accept only Cloudflare's client certificate, continue with Mutual TLS with Cloudflare.