These are the steps of native mode, done by hand. Zerodot runs as four systemd services. Postgres and Valkey run on the server.
In the examples:
- The instance name is
zerodot. It is also the system user, the database and the database user. - The install folder is
/var/www/zerodot. - The domain is
zerodot.example.com. - The ports are 3000 (web), 3003 (API), 3001 (worker) and 3002 (sandbox). If a port is in use, pick another one and use it in all steps.
1. Install the packages
You need Git, the build tools (the code sandbox has a native module), Postgres and Valkey.
Debian and Ubuntu:
sudo apt update
sudo apt install -y git curl openssl ca-certificates iproute2 xz-utils python3 make g++ postgresql
sudo apt install -y valkey-server || sudo apt install -y redis-server
Fedora, RHEL, Rocky and Alma:
sudo dnf install -y git curl openssl ca-certificates iproute xz python3 make gcc-c++ postgresql-server postgresql
sudo dnf install -y valkey || sudo dnf install -y redis
Arch:
sudo pacman -S --needed git curl openssl ca-certificates iproute2 xz python make gcc postgresql valkey
Do not run pacman -Sy alone. If a package is not found, run sudo pacman -Syu (a full upgrade) first.
2. Set up Postgres
Debian and Ubuntu make and start the database cluster. Skip to step 3.
Fedora, RHEL, Rocky and Alma:
sudo PGSETUP_INITDB_OPTIONS="--auth-local=peer --auth-host=scram-sha-256" postgresql-setup --initdb
sudo systemctl enable --now postgresql
Arch:
sudo -u postgres initdb -D /var/lib/postgres/data -E UTF8 --locale=C.UTF-8 --auth-local=peer --auth-host=scram-sha-256
sudo systemctl enable --now postgresql
If Postgres runs already (13 or newer), do not make a new data folder. Use it as it is.
3. Make the database
PASS=$(openssl rand -hex 24)
sudo -u postgres psql -c "create role zerodot login password '$PASS'"
sudo -u postgres psql -c "create database zerodot owner zerodot"
echo "$PASS"
Keep the password for step 8. Test the login:
PGPASSWORD="$PASS" psql -h 127.0.0.1 -U zerodot -d zerodot -c 'select 1'
If the login fails with ident authentication failed (Fedora, RHEL), add password lines for this user. Find the file:
sudo -u postgres psql -Atc 'show hba_file'
Make a copy of the file. Then add these lines before the first rule:
host zerodot zerodot 127.0.0.1/32 scram-sha-256
host zerodot zerodot ::1/128 scram-sha-256
Reload Postgres:
sudo -u postgres psql -c 'select pg_reload_conf()'
4. Set up Valkey
The job queue needs noeviction. If Valkey is new on this server, add these lines to the end of its config file. The file is /etc/valkey/valkey.conf, /etc/redis/redis.conf or /etc/redis.conf.
maxmemory-policy noeviction
appendonly yes
bind 127.0.0.1 -::1
Start it. Use the name of the unit on your system: valkey-server, valkey, redis-server or redis.
sudo systemctl enable valkey-server
sudo systemctl restart valkey-server
If Valkey runs already and other apps use it, do not change its config. Check the policy:
valkey-cli config get maxmemory-policy
Use a free database number from 1 to 15. See Databases.
5. Install Node 22
You need Node 22 or newer. The service user must be able to read it. A Node in a home folder (nvm) does not work.
If the server has a fitting Node in /usr/bin or /usr/local/bin, use it. Else install a private copy in /opt/zerodot-node. Use x64 on x86_64 and arm64 on aarch64:
ARCH=x64
cd /tmp
curl -fsSLO https://nodejs.org/dist/latest-v22.x/SHASUMS256.txt
FILE=$(awk -v a="linux-$ARCH.tar.xz" '$2 ~ a"$" {print $2}' SHASUMS256.txt)
curl -fsSLO "https://nodejs.org/dist/latest-v22.x/$FILE"
grep " $FILE\$" SHASUMS256.txt | sha256sum -c -
sudo mkdir -p /opt/zerodot-node
sudo tar -xJf "$FILE" -C /opt/zerodot-node
sudo ln -sfn "/opt/zerodot-node/${FILE%.tar.xz}" /opt/zerodot-node/current
/opt/zerodot-node/current/bin/node -v
The steps below use /opt/zerodot-node/current. If you use the system Node, use /usr in place of it.
6. Get the code
sudo mkdir -p /var/www
sudo git clone https://github.com/zerodot-io/zerodot.git /var/www/zerodot
cd /var/www/zerodot
7. Install pnpm
The code needs one exact pnpm version. The lockfile depends on it. Read it from package.json:
PM_VER=$(sed -n 's/.*"packageManager": *"pnpm@\([^"]*\)".*/\1/p' package.json)
echo "$PM_VER"
Install it in its own folder:
sudo env PATH="/opt/zerodot-node/current/bin:$PATH" npm install -g --prefix "/opt/zerodot-tools/pnpm-$PM_VER" "pnpm@$PM_VER"
8. Settings
sudo cp .env.example .env
sudo sed -i "s|^ZERODOT_SECRET_KEY=.*|ZERODOT_SECRET_KEY=$(openssl rand -base64 32)|" .env
sudo sed -i "s|^BETTER_AUTH_SECRET=.*|BETTER_AUTH_SECRET=$(openssl rand -base64 32)|" .env
sudo sed -i "s|^ZERODOT_BASE_URL=.*|ZERODOT_BASE_URL=https://zerodot.example.com|" .env
sudo sed -i "s|^ZERODOT_TRUST_PROXY=.*|ZERODOT_TRUST_PROXY=true|" .env
sudo sed -i "s|^DATABASE_URL=.*|DATABASE_URL=postgres://zerodot:$PASS@127.0.0.1:5432/zerodot|" .env
sudo sed -i "s|^VALKEY_URL=.*|VALKEY_URL=redis://127.0.0.1:6379/1|" .env
sudo sed -i "s|^SANDBOX_URL=.*|SANDBOX_URL=http://127.0.0.1:3002|" .env
sudo sed -i "s|^ZERODOT_BLOB_DIR=.*|ZERODOT_BLOB_DIR=/var/lib/zerodot/blobs|" .env
echo "ZERODOT_NODES_DIR=/var/lib/zerodot/nodes" | sudo tee -a .env
$PASS is the database password from step 3. Use the Valkey database number from step 4.
ZERODOT_NODES_DIR keeps the node packages that an admin installs. The script sets the same value. The web service runs in apps/web, and the other services run in the install folder. One absolute folder makes sure that all services use the same packages.
Make a copy of ZERODOT_SECRET_KEY. Keep it in a safe place.
9. Build
cd /var/www/zerodot
export PATH="/opt/zerodot-node/current/bin:/opt/zerodot-tools/pnpm-$PM_VER/bin:$PATH"
export CXXFLAGS="-include cstdint"
sudo env PATH="$PATH" CXXFLAGS="$CXXFLAGS" TURBO_TELEMETRY_DISABLED=1 DO_NOT_TRACK=1 pnpm install --frozen-lockfile
sudo env PATH="$PATH" TURBO_TELEMETRY_DISABLED=1 DO_NOT_TRACK=1 pnpm run build
CXXFLAGS="-include cstdint" is necessary on systems with GCC 13 or newer (for example Fedora 44 with GCC 16). Without it, the code sandbox module (isolated-vm) does not compile: the error is 'uint32_t' was not declared. On older compilers, the flag does no harm. The install script sets the same flag.
The first build takes about 10 minutes. It needs 4 GB of RAM, or 2 GB and swap. If it stops with no clear error, check for low memory: free -m and sudo dmesg | grep -i oom.
10. Make the system user
sudo useradd --system --user-group --home-dir /var/www/zerodot --shell "$(command -v nologin || echo /usr/sbin/nologin)" zerodot
sudo chown -R zerodot:zerodot /var/www/zerodot
sudo mkdir -p /var/lib/zerodot/blobs /var/lib/zerodot/nodes
sudo chown -R zerodot:zerodot /var/lib/zerodot
sudo chown root:zerodot /var/www/zerodot/.env
sudo chmod 640 /var/www/zerodot/.env
The service user can read .env but cannot change it.
On Fedora and RHEL with SELinux enforcing, systemd cannot read .env in a new folder under /var/www. The file has the label var_t. Give it the label etc_t:
sudo dnf install -y policycoreutils-python-utils
sudo semanage fcontext -a -t etc_t '/var/www/zerodot/\.env'
sudo restorecon -v /var/www/zerodot/.env
The install script does the same. To undo, run sudo semanage fcontext -d '/var/www/zerodot/\.env' and then sudo restorecon -v /var/www/zerodot/.env.
11. Write the services
All four services use the same hardening:
| Setting | What it does |
|---|---|
User, Group |
Run as the system user, not as root. |
NoNewPrivileges=true |
The process cannot get more rights. |
PrivateTmp=true |
An own /tmp. |
ProtectSystem=full |
/usr, /boot and /etc are read-only. |
ProtectHome=true |
No access to /home and /root. |
Restart=always |
Restart after a crash, after 3 seconds. |
ZERODOT_BIND_HOST=127.0.0.1 |
Listen on localhost only. |
The sandbox runs code from users. It must never be reachable from the internet. It gets no .env, so it has no secrets.
Sandbox:
sudo tee /etc/systemd/system/zerodot-sandbox.service >/dev/null <<'UNIT'
[Unit]
Description=Zerodot code sandbox (zerodot)
After=network.target
[Service]
User=zerodot
Group=zerodot
WorkingDirectory=/var/www/zerodot
Environment=PATH=/opt/zerodot-node/current/bin:/usr/local/bin:/usr/bin:/bin
Environment=NODE_ENV=production
Restart=always
RestartSec=3
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=full
ProtectHome=true
Environment=PORT=3002
Environment=ZERODOT_BIND_HOST=127.0.0.1
ExecStart=/opt/zerodot-node/current/bin/node --no-node-snapshot apps/sandbox/dist/index.js
[Install]
WantedBy=multi-user.target
UNIT
API. Use the Valkey unit of your system in After=:
sudo tee /etc/systemd/system/zerodot-api.service >/dev/null <<'UNIT'
[Unit]
Description=Zerodot API (zerodot)
After=network.target postgresql.service valkey-server.service
[Service]
User=zerodot
Group=zerodot
WorkingDirectory=/var/www/zerodot
Environment=PATH=/opt/zerodot-node/current/bin:/usr/local/bin:/usr/bin:/bin
Environment=NODE_ENV=production
Restart=always
RestartSec=3
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=full
ProtectHome=true
EnvironmentFile=/var/www/zerodot/.env
Environment=ZERODOT_API_PORT=3003
Environment=ZERODOT_BIND_HOST=127.0.0.1
ExecStart=/opt/zerodot-node/current/bin/node apps/api/dist/index.js
[Install]
WantedBy=multi-user.target
UNIT
Worker:
sudo tee /etc/systemd/system/zerodot-worker.service >/dev/null <<'UNIT'
[Unit]
Description=Zerodot worker (zerodot)
After=network.target postgresql.service valkey-server.service zerodot-sandbox.service
[Service]
User=zerodot
Group=zerodot
WorkingDirectory=/var/www/zerodot
Environment=PATH=/opt/zerodot-node/current/bin:/usr/local/bin:/usr/bin:/bin
Environment=NODE_ENV=production
Restart=always
RestartSec=3
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=full
ProtectHome=true
EnvironmentFile=/var/www/zerodot/.env
Environment=PORT=3001
Environment=ZERODOT_BIND_HOST=127.0.0.1
ExecStart=/opt/zerodot-node/current/bin/node apps/worker/dist/index.js
[Install]
WantedBy=multi-user.target
UNIT
Web. ZERODOT_API_PORT makes the web app send the API paths to the API app. Then one port serves the whole app:
sudo tee /etc/systemd/system/zerodot-web.service >/dev/null <<'UNIT'
[Unit]
Description=Zerodot web (zerodot)
After=network.target postgresql.service valkey-server.service zerodot-api.service
[Service]
User=zerodot
Group=zerodot
WorkingDirectory=/var/www/zerodot/apps/web
Environment=PATH=/opt/zerodot-node/current/bin:/usr/local/bin:/usr/bin:/bin
Environment=NODE_ENV=production
Restart=always
RestartSec=3
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=full
ProtectHome=true
EnvironmentFile=/var/www/zerodot/.env
Environment=ZERODOT_API_PORT=3003
ExecStart=/opt/zerodot-node/current/bin/node node_modules/vite/bin/vite.js preview --host 127.0.0.1 --port 3000
[Install]
WantedBy=multi-user.target
UNIT
12. Start the services
sudo systemctl daemon-reload
sudo systemctl enable zerodot-sandbox zerodot-api zerodot-worker zerodot-web
sudo systemctl restart zerodot-sandbox zerodot-api zerodot-worker zerodot-web
curl -sI http://127.0.0.1:3000/
The curl command must show 307 with Location: /sign-in.
13. Proxy
Set up one proxy:
- Caddy
- nginx
- Cloudflare Tunnel
- Other proxies. A proxy in Docker cannot reach
127.0.0.1on the server.
14. Firewall
With ufw:
sudo ufw allow OpenSSH
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw --force enable
With firewalld:
sudo firewall-cmd --permanent --add-service=http --add-service=https
sudo firewall-cmd --add-service=http --add-service=https
Do not open ports 3000 to 3003. The services listen on 127.0.0.1 only.
15. First sign-in
- Open
https://zerodot.example.comand sign up. The first user is the instance admin. - Open System > Instance and turn Public signup off.
Update
cd /var/www/zerodot
sudo -u zerodot env HOME=/var/www/zerodot git -C /var/www/zerodot pull --ff-only
PM_VER=$(sed -n 's/.*"packageManager": *"pnpm@\([^"]*\)".*/\1/p' package.json)
export PATH="/opt/zerodot-node/current/bin:/opt/zerodot-tools/pnpm-$PM_VER/bin:$PATH"
sudo env PATH="$PATH" npm install -g --prefix "/opt/zerodot-tools/pnpm-$PM_VER" "pnpm@$PM_VER"
sudo env PATH="$PATH" CXXFLAGS="-include cstdint" pnpm install --frozen-lockfile
sudo env PATH="$PATH" pnpm run build
sudo chown -R zerodot:zerodot /var/www/zerodot
sudo chown root:zerodot .env
sudo systemctl restart zerodot-sandbox zerodot-api zerodot-worker zerodot-web
- The folder belongs to the
zerodotuser. Rungitas this user, withHOMEset to the install folder. As root, Git refuses to work in the folder ("detected dubious ownership"). The install script does the same. - Read
PM_VERaftergit pull. A new release can need a new pnpm version.