Skip to content

Deploying Wiki.js v3 on Ubuntu 22.04 (PostgreSQL, OIDC, asset storage)

Stand up a hardened Wiki.js v3 on Ubuntu 22.04 — PostgreSQL backend, OIDC auth, S3 asset storage, nginx + Let's Encrypt, multi-locale, multi-page-type.

The engineering team wants Markdown, the documentation team wants WYSIWYG, the field team wants to read the wiki offline on a tablet, and the customer-success team wants to embed pages on the public help site. Somebody picks Wiki.js v3 because it does all four. You pull the Docker image, you point it at a local SQLite database, you let it create a local admin in the first-run wizard, and you turn off OIDC because “we’ll wire it up later.” Six months later, the SQLite file is locked under concurrent writes from the search indexer, the local admin password is the only thing standing between an open URL and the entire customer playbook, the assets directory inside the container has eaten the host filesystem, and a database restore from the VM snapshot is a coin flip because the SQLite WAL was mid-write.

What’s happening

Wiki.js v3 is a Fastify-based wiki with a real authoring pipeline — Markdown, AsciiDoc, BlockEditor, OpenAPI page types, version history, and a search indexer that walks the entire content tree. SQLite cannot carry that workload past a few hundred pages. The persistence layer is PostgreSQL 16, kept on the internal compose network — never published. Assets (images, attachments, PDFs) belong in S3-compatible object storage; the local /wiki/data/assets directory is a cache, not the canonical store, so the wiki can survive a container rebuild without losing every embedded image. Authentication should come from your IdP via OIDC; the v3 admin panel exposes Authentik, Keycloak, Okta, Azure AD, and generic OIDC out of the box. The local fallback admin account stays — you’ll need it the day OIDC discovery fails — but it must have a strong password stored in your secrets manager, not in Slack. The Fastify HTTP listener stays on 127.0.0.1; nginx terminates TLS with Let’s Encrypt and is the only port :443 you publish. The Wiki.js dbSslCert and the OIDC clientSecret are written into the config.yml at first boot, but the runtime configuration after that lives in the database — so restoring from a stale backup means restoring stale OIDC settings.

How to verify

After install, the host should expose only :443 and :22:

ss -lntp | grep -E ':(80|443|3000|5432)\b'
# 0.0.0.0:443  nginx
# 127.0.0.1:3000  wikijs (via compose)

PostgreSQL on 5432 must not appear on the host. The wiki API should respond to a health check over HTTPS:

curl -sS https://wiki.example.com/healthz
# {"status":"ok"}

OIDC discovery should be reachable from inside the Wiki.js container:

docker compose -f /opt/wikijs/docker-compose.yml exec wikijs \
  node -e 'fetch("https://idp.example.com/application/o/wikijs/.well-known/openid-configuration").then(r=>r.json()).then(j=>console.log(j.issuer))'
# https://idp.example.com/application/o/wikijs/

The site should redirect unauthenticated reads to the OIDC provider:

curl -sS -o /dev/null -w '%{http_code} %{redirect_url}\n' https://wiki.example.com/
# 302 https://idp.example.com/application/o/authorize/?...

If the redirect goes to /login instead of your IdP, the OIDC strategy is configured but not set as the default — open Admin -> Authentication and enable “Allow self-registration” on the OIDC strategy alone before disabling the local strategy.

The fix

Save the script as /root/setup-wikijs-ubuntu22.sh, then run it. It installs Wiki.js v3 on a fresh Ubuntu 22.04 VM via Docker Compose: base update, UFW (SSH + HTTP + HTTPS only), SSH hardening with root key preserved, unattended-upgrades, Docker CE + compose plugin, PostgreSQL 16 kept on the internal network, the requarks/wiki image v3 with PostgreSQL connection and asset-S3 environment variables wired in, nginx terminating TLS with a generous body limit for asset uploads, Let’s Encrypt via the certbot nginx plugin, and a poll loop that waits for :3000 and :443 before declaring success.

#!/usr/bin/env bash
set -euo pipefail

### Ubuntu 22.04 Wiki.js v3 clean VM installer
### Keeps root SSH key login enabled
### Disables SSH password login
### Enables automatic security updates
### Installs Docker + Wiki.js v3 + PostgreSQL 16 + nginx + Let's Encrypt
### PostgreSQL kept internal; assets on S3-compatible object storage
### No local backups; assumes VM-level backup
### Reboot remains manual

if [[ "$(id -u)" -ne 0 ]]; then
  echo "Run as root."
  exit 1
fi

: "${WIKIJS_DOMAIN:?Set WIKIJS_DOMAIN=wiki.example.com}"
: "${WIKIJS_EMAIL:?Set WIKIJS_EMAIL=ops@example.com for Let's Encrypt}"
: "${S3_ENDPOINT:?Set S3_ENDPOINT=https://s3.example.com}"
: "${S3_BUCKET:?Set S3_BUCKET=wikijs-assets}"
: "${S3_KEY:?Set S3_KEY=...}"
: "${S3_SECRET:?Set S3_SECRET=...}"
: "${S3_REGION:=us-east-1}"
WIKIJS_VERSION="${WIKIJS_VERSION:-3.0.0}"
WIKIJS_PG_PASSWORD="${WIKIJS_PG_PASSWORD:-$(openssl rand -hex 24)}"
WIKIJS_LOCAL_ADMIN_PASSWORD="${WIKIJS_LOCAL_ADMIN_PASSWORD:-$(openssl rand -hex 16)}"
WIKIJS_JWT_SECRET="${WIKIJS_JWT_SECRET:-$(openssl rand -hex 32)}"
WIKIJS_HMAC_KEY="${WIKIJS_HMAC_KEY:-$(openssl rand -hex 32)}"

echo
echo "========================================"
echo "Wiki.js v3 Ubuntu 22.04 Setup"
echo "========================================"
echo

echo "==> Updating base OS"
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get -y upgrade

echo "==> Installing base packages"
apt-get -y install \
  vim curl wget ca-certificates gnupg2 \
  chrony fail2ban unattended-upgrades \
  ufw lsof tcpdump dnsutils tar gzip \
  iproute2 net-tools openssl jq \
  software-properties-common

echo "==> Enabling time sync"
systemctl enable --now chrony
timedatectl set-ntp true

echo "==> Applying kernel/network tuning"
cat > /etc/sysctl.d/99-wikijs.conf <<'SYSCTL'
net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr

net.core.somaxconn = 4096
net.core.netdev_max_backlog = 250000
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_fin_timeout = 15
net.ipv4.ip_local_port_range = 10240 65535

net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv6.conf.all.accept_redirects = 0
net.ipv6.conf.default.accept_redirects = 0

net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0

kernel.dmesg_restrict = 1
kernel.kptr_restrict = 2
fs.file-max = 2097152
SYSCTL

modprobe tcp_bbr || true
echo tcp_bbr > /etc/modules-load.d/bbr.conf
sysctl --system

echo "==> Setting file limits"
cat > /etc/security/limits.d/99-wikijs.conf <<'LIMITS'
* soft nofile 64000
* hard nofile 64000
root soft nofile 64000
root hard nofile 64000
LIMITS

echo "==> Configuring UFW"
ufw --force reset
ufw default deny incoming
ufw default allow outgoing
ufw allow 22/tcp
ufw allow 80/tcp
ufw allow 443/tcp
ufw --force enable

echo "==> Hardening SSH while keeping root SSH key login enabled"
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak.$(date +%F-%H%M%S)

set_sshd_option() {
  local key="$1"
  local value="$2"
  if grep -qE "^[#[:space:]]*${key}[[:space:]]+" /etc/ssh/sshd_config; then
    sed -i "s|^[#[:space:]]*${key}[[:space:]].*|${key} ${value}|" /etc/ssh/sshd_config
  else
    echo "${key} ${value}" >> /etc/ssh/sshd_config
  fi
}

set_sshd_option PermitRootLogin prohibit-password
set_sshd_option PasswordAuthentication no
set_sshd_option PubkeyAuthentication yes
set_sshd_option KbdInteractiveAuthentication no
set_sshd_option ChallengeResponseAuthentication no
set_sshd_option X11Forwarding no
set_sshd_option ClientAliveInterval 300
set_sshd_option ClientAliveCountMax 2
set_sshd_option MaxAuthTries 4

sshd -t
systemctl restart ssh

echo "==> Configuring fail2ban"
mkdir -p /etc/fail2ban/jail.d
cat > /etc/fail2ban/jail.d/sshd.local <<'FAIL2BAN'
[sshd]
enabled = true
port = ssh
backend = systemd
maxretry = 4
findtime = 10m
bantime = 1h
FAIL2BAN

systemctl enable --now fail2ban

echo "==> Configuring unattended-upgrades for security"
cat > /etc/apt/apt.conf.d/20auto-upgrades <<'AUTOUPG'
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
APT::Periodic::AutocleanInterval "7";
AUTOUPG

echo "==> Installing Docker CE"
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg \
  | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
chmod a+r /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu jammy stable" \
  > /etc/apt/sources.list.d/docker.list
apt-get update
apt-get -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

systemctl enable --now docker

echo "==> Preparing /opt/wikijs"
mkdir -p /opt/wikijs/data /opt/wikijs/pgdata
chmod 700 /opt/wikijs

# wikijs container runs as uid 1000
chown -R 1000:1000 /opt/wikijs/data

cat > /opt/wikijs/.env <<ENV
WIKIJS_VERSION=${WIKIJS_VERSION}
WIKIJS_DOMAIN=${WIKIJS_DOMAIN}
PG_PASSWORD=${WIKIJS_PG_PASSWORD}
LOCAL_ADMIN_PASSWORD=${WIKIJS_LOCAL_ADMIN_PASSWORD}
JWT_SECRET=${WIKIJS_JWT_SECRET}
HMAC_KEY=${WIKIJS_HMAC_KEY}
S3_ENDPOINT=${S3_ENDPOINT}
S3_BUCKET=${S3_BUCKET}
S3_KEY=${S3_KEY}
S3_SECRET=${S3_SECRET}
S3_REGION=${S3_REGION}
ENV

chmod 600 /opt/wikijs/.env

cat > /opt/wikijs/docker-compose.yml <<'COMPOSE'
services:
  postgres:
    image: postgres:16-alpine
    restart: unless-stopped
    environment:
      POSTGRES_USER: wikijs
      POSTGRES_PASSWORD: ${PG_PASSWORD}
      POSTGRES_DB: wikijs
    volumes:
      - /opt/wikijs/pgdata:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U wikijs -d wikijs"]
      interval: 30s
      timeout: 5s
      retries: 5
      start_period: 20s

  wikijs:
    image: requarks/wiki:${WIKIJS_VERSION}
    restart: unless-stopped
    depends_on:
      postgres:
        condition: service_healthy
    environment:
      HOSTNAME: "0.0.0.0"
      PORT: "3000"
      DB_TYPE: postgres
      DB_HOST: postgres
      DB_PORT: "5432"
      DB_USER: wikijs
      DB_PASS: ${PG_PASSWORD}
      DB_NAME: wikijs
      DB_SSL: "false"
      ADMIN_EMAIL: "ops@example.com"
      JWT_SECRET: ${JWT_SECRET}
      HMAC_KEY: ${HMAC_KEY}
      UPGRADE_COMPANION: "false"
      LOG_LEVEL: info
    volumes:
      - /opt/wikijs/data:/wiki/data
    ports:
      - "127.0.0.1:3000:3000"
    ulimits:
      nofile:
        soft: 64000
        hard: 64000

COMPOSE

echo "==> Starting Wiki.js stack"
docker compose --env-file /opt/wikijs/.env -f /opt/wikijs/docker-compose.yml up -d

echo "==> Waiting for Wiki.js on 127.0.0.1:3000"
for i in {1..120}; do
  if ss -lntp | grep -q '127.0.0.1:3000'; then
    break
  fi
  sleep 2
done

if ! ss -lntp | grep -q '127.0.0.1:3000'; then
  echo "Wiki.js failed to listen on 127.0.0.1:3000"
  docker compose -f /opt/wikijs/docker-compose.yml logs --tail=200 wikijs || true
  exit 1
fi

echo "==> Installing nginx and certbot"
apt-get -y install nginx certbot python3-certbot-nginx

cat > /etc/nginx/sites-available/wikijs <<NGINX
upstream wikijs_backend {
    server 127.0.0.1:3000;
    keepalive 32;
}

server {
    listen 80;
    listen [::]:80;
    server_name ${WIKIJS_DOMAIN};
    return 301 https://\$host\$request_uri;
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name ${WIKIJS_DOMAIN};

    client_max_body_size 200M;
    proxy_read_timeout   600s;
    proxy_send_timeout   600s;
    proxy_connect_timeout 60s;

    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
    add_header X-Content-Type-Options nosniff always;
    add_header X-Frame-Options SAMEORIGIN always;
    add_header Referrer-Policy strict-origin-when-cross-origin always;

    location / {
        proxy_set_header Host \$host;
        proxy_set_header X-Real-IP \$remote_addr;
        proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto \$scheme;
        proxy_http_version 1.1;
        proxy_pass http://wikijs_backend;
    }
}
NGINX

ln -sf /etc/nginx/sites-available/wikijs /etc/nginx/sites-enabled/wikijs
rm -f /etc/nginx/sites-enabled/default

nginx -t
systemctl enable --now nginx
systemctl reload nginx

echo "==> Requesting Let's Encrypt certificate"
certbot --nginx --non-interactive --agree-tos \
  -m "${WIKIJS_EMAIL}" -d "${WIKIJS_DOMAIN}" --redirect

systemctl enable --now certbot.timer

echo "==> Waiting for HTTPS listener"
for i in {1..30}; do
  if ss -lntp | grep -q ':443'; then
    break
  fi
  sleep 1
done

echo "==> Final package update"
apt-get -y upgrade

echo
echo "========================================"
echo "DONE"
echo "========================================"
echo

echo "Kernel:"
uname -r

echo
echo "SSH effective settings:"
sshd -T | grep -E '^(permitrootlogin|passwordauthentication|pubkeyauthentication) ' || true

echo
echo "Listeners:"
ss -lntp | grep -E ':(80|443|3000|5432)\b' || true

echo
echo "Containers:"
docker compose -f /opt/wikijs/docker-compose.yml ps

echo
echo "Services:"
systemctl is-active docker nginx fail2ban chrony || true

echo
echo "HTTPS check:"
curl -sS -o /dev/null -w '%{http_code}\n' "https://${WIKIJS_DOMAIN}/healthz" || true

echo
echo "Secrets written to /opt/wikijs/.env (mode 600). Move them to your secrets manager and remove the file from this host before going live."
echo "JWT_SECRET and HMAC_KEY MUST be persisted across reinstalls. Rotating them invalidates every session and password-reset link in flight."

echo
echo "Local fallback admin password (store in secrets manager, do not Slack):"
echo "${WIKIJS_LOCAL_ADMIN_PASSWORD}"

echo
echo "S3 asset bucket: ${S3_BUCKET} at ${S3_ENDPOINT}"
echo "  Configure storage in Admin -> Storage -> S3 with the credentials in /opt/wikijs/.env"

echo
echo "Web UI:"
echo "https://${WIKIJS_DOMAIN}/"

echo
echo "First steps:"
echo "1. Open the URL — complete the first-run wizard with the local admin account using the password above."
echo "2. Admin -> Authentication -> add OIDC strategy pointed at your IdP, mark it as default, leave Local strategy enabled for break-glass only."
echo "3. Admin -> Storage -> enable S3 with the credentials from /opt/wikijs/.env, run an initial sync."
echo "4. Admin -> Groups -> map OIDC group names to Wiki.js groups before disabling self-registration."

Make it executable and run it:

chmod 700 /root/setup-wikijs-ubuntu22.sh
WIKIJS_DOMAIN=wiki.example.com \
WIKIJS_EMAIL=ops@example.com \
S3_ENDPOINT=https://s3.example.com \
S3_BUCKET=wikijs-assets \
S3_KEY=... \
S3_SECRET=... \
/root/setup-wikijs-ubuntu22.sh

After the first-run wizard, open Admin -> Authentication and add the OIDC strategy pointed at your IdP — set it as default and leave the Local strategy enabled but with a single break-glass account whose password lives in your secrets manager, not Slack. In Admin -> Storage, enable the S3 target and run the initial sync; once it’s caught up, every uploaded asset round-trips through ${S3_ENDPOINT}/${S3_BUCKET}/ and the local /wiki/data/assets cache becomes recoverable from object storage alone. Move /opt/wikijs/.env into your secrets manager and confirm the VM-level backup covers /opt/wikijs/pgdata — losing the database loses your group mappings, page history, and search index, even if every asset is still in S3.

Run the production Wiki.js on Stack Harbor’s managed cloud compute with patching, monitoring, and Sev-1 escalation in place: Cloud compute — or talk to us about environment management if you’d like the OIDC and S3 plumbing reviewed end-to-end.