Skip to content

Deploying AnythingLLM private RAG on Ubuntu 22.04 (production-ready)

Stand up a hardened AnythingLLM on Ubuntu 22.04 via Docker — PostgreSQL backend, LanceDB or Qdrant vector store, multi-user auth, nginx + Let's Encrypt.

You’ve been asked to stand up AnythingLLM so the operations team can ask questions of the runbooks, the contracts team can query the policy library, and HR can search the handbook — each in its own workspace, each with its own LLM provider. The Docker quickstart works, the first PDFs are uploaded, retrieval looks good. Six months later, the single shared admin password is in three Slack threads, the JWT secret is the upstream default because nobody set the env var, the embeddings the contracts team uploaded sit in the same vector index as the HR handbook because workspaces were never enforced as data-scoping boundaries, and the SQLite database has been mounted into a host directory the VM-level backup ignores.

What’s happening

An AnythingLLM deployment that actually replaces a shared chat-with-PDFs prototype needs more than docker run mintplexlabs/anythingllm. The persistence layer should be PostgreSQL, not SQLite — multi-user workspaces with per-thread chat history and per-document permissions push concurrent writes that SQLite handles by serializing every request behind a global lock. PostgreSQL has to stay on the internal compose network — never published. The vector store should be either Qdrant (when you already operate one) or LanceDB on a persistent volume; either way, the data has to sit somewhere the VM-level backup covers. The web container sits behind nginx with Let’s Encrypt; the host should publish :443 only. Multi-user mode must be enabled at first boot so workspaces become real data-scoping boundaries — the default single-user mode lets anyone with the URL see every document. The JWT_SECRET and the auth password hash salt must be set explicitly and persisted; rotating them invalidates every existing session and password reset link in flight.

How to verify

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

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

PostgreSQL on 5432 and Qdrant on 6333 must not appear on the host. The auth endpoint must require credentials:

curl -sS -o /dev/null -w '%{http_code}\n' https://chat.example.com/api/system/check-token
# 401 (without Authorization)

The system info endpoint over HTTPS must return JSON only after a workspace API key is presented:

curl -sS -H "Authorization: Bearer $WORKSPACE_API_KEY" \
  https://chat.example.com/api/v1/system | jq .Authentication

If the auth endpoint returns 200 without a bearer header, multi-user mode is off and every workspace is open — turn it on before another document is uploaded.

The fix

Save the script below as /root/setup-anythingllm-ubuntu22.sh, then run it. It installs AnythingLLM 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 kept on the internal network, an optional Qdrant sidecar on the internal network (set VECTOR_DB=qdrant; otherwise LanceDB is used on a persistent volume), the AnythingLLM container with multi-user mode forced on via AUTH_TOKEN and JWT_SECRET written to /opt/anythingllm/.env with chmod 600, nginx terminating TLS with a generous body limit for document uploads, Let’s Encrypt via the certbot nginx plugin, and a poll loop that waits for :3001 and :443 before declaring success.

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

### Ubuntu 22.04 AnythingLLM clean VM installer
### Keeps root SSH key login enabled
### Disables SSH password login
### Enables automatic security updates
### Installs and configures Docker + AnythingLLM + PostgreSQL (+ optional Qdrant) + nginx + Let's Encrypt
### Multi-user mode forced; JWT_SECRET persisted; vector store on a persistent volume
### No local backups; assumes VM-level backup
### Vector indexes can be rebuilt from source docs, but reproducibility is slow.
### Reboot remains manual

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

: "${ANYTHINGLLM_DOMAIN:?Set ANYTHINGLLM_DOMAIN=chat.example.com}"
: "${ANYTHINGLLM_EMAIL:?Set ANYTHINGLLM_EMAIL=ops@example.com for Let's Encrypt}"
ANYTHINGLLM_VERSION="${ANYTHINGLLM_VERSION:-1.7.2}"
VECTOR_DB="${VECTOR_DB:-lancedb}"   # lancedb | qdrant
ANYTHINGLLM_PG_PASSWORD="${ANYTHINGLLM_PG_PASSWORD:-$(openssl rand -hex 24)}"
ANYTHINGLLM_AUTH_TOKEN="${ANYTHINGLLM_AUTH_TOKEN:-$(openssl rand -hex 32)}"
ANYTHINGLLM_JWT_SECRET="${ANYTHINGLLM_JWT_SECRET:-$(openssl rand -hex 32)}"
ANYTHINGLLM_SIG_KEY="${ANYTHINGLLM_SIG_KEY:-$(openssl rand -hex 32)}"
ANYTHINGLLM_SIG_SALT="${ANYTHINGLLM_SIG_SALT:-$(openssl rand -hex 32)}"
ANYTHINGLLM_QDRANT_API_KEY="${ANYTHINGLLM_QDRANT_API_KEY:-$(openssl rand -hex 32)}"

echo
echo "========================================"
echo "AnythingLLM 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-anythingllm.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
vm.max_map_count = 262144
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-anythingllm.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/anythingllm"
mkdir -p /opt/anythingllm/storage /opt/anythingllm/hotdir /opt/anythingllm/outputs \
         /var/lib/qdrant/storage /var/lib/qdrant/snapshots
chmod 700 /opt/anythingllm /var/lib/qdrant /var/lib/qdrant/storage /var/lib/qdrant/snapshots

# AnythingLLM image runs as uid 1000 by default
chown -R 1000:1000 /opt/anythingllm/storage /opt/anythingllm/hotdir /opt/anythingllm/outputs

cat > /opt/anythingllm/.env <<ENV
ANYTHINGLLM_VERSION=${ANYTHINGLLM_VERSION}
ANYTHINGLLM_DOMAIN=${ANYTHINGLLM_DOMAIN}
VECTOR_DB=${VECTOR_DB}
PG_PASSWORD=${ANYTHINGLLM_PG_PASSWORD}
AUTH_TOKEN=${ANYTHINGLLM_AUTH_TOKEN}
JWT_SECRET=${ANYTHINGLLM_JWT_SECRET}
SIG_KEY=${ANYTHINGLLM_SIG_KEY}
SIG_SALT=${ANYTHINGLLM_SIG_SALT}
QDRANT_API_KEY=${ANYTHINGLLM_QDRANT_API_KEY}
ENV

chmod 600 /opt/anythingllm/.env

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

  qdrant:
    image: qdrant/qdrant:v1.12.4
    restart: unless-stopped
    profiles: ["qdrant"]
    environment:
      QDRANT__SERVICE__API_KEY: ${QDRANT_API_KEY}
      QDRANT__TELEMETRY_DISABLED: "true"
    volumes:
      - /var/lib/qdrant/storage:/qdrant/storage
      - /var/lib/qdrant/snapshots:/qdrant/snapshots

  anythingllm:
    image: mintplexlabs/anythingllm:${ANYTHINGLLM_VERSION}
    restart: unless-stopped
    depends_on:
      postgres:
        condition: service_healthy
    cap_add:
      - SYS_ADMIN
    environment:
      SERVER_PORT: 3001
      STORAGE_DIR: /app/server/storage
      DATABASE_CONNECTION_STRING: postgresql://anythingllm:${PG_PASSWORD}@postgres:5432/anythingllm
      MULTI_USER_MODE: "true"
      DISABLE_TELEMETRY: "true"
      AUTH_TOKEN: ${AUTH_TOKEN}
      JWT_SECRET: ${JWT_SECRET}
      SIG_KEY: ${SIG_KEY}
      SIG_SALT: ${SIG_SALT}
      VECTOR_DB: ${VECTOR_DB}
      QDRANT_ENDPOINT: http://qdrant:6333
      QDRANT_API_KEY: ${QDRANT_API_KEY}
      LANCEDB_PATH: /app/server/storage/lancedb
      LLM_PROVIDER: openai
      WHISPER_PROVIDER: local
      TTS_PROVIDER: native
      EMBEDDING_ENGINE: native
    volumes:
      - /opt/anythingllm/storage:/app/server/storage
      - /opt/anythingllm/hotdir:/app/collector/hotdir
      - /opt/anythingllm/outputs:/app/collector/outputs
    ports:
      - "127.0.0.1:3001:3001"
    ulimits:
      nofile:
        soft: 64000
        hard: 64000

volumes:
  pgdata:
    driver: local
COMPOSE

echo "==> Starting AnythingLLM stack (${VECTOR_DB})"
if [[ "${VECTOR_DB}" == "qdrant" ]]; then
  docker compose --env-file /opt/anythingllm/.env --profile qdrant -f /opt/anythingllm/docker-compose.yml up -d
else
  docker compose --env-file /opt/anythingllm/.env -f /opt/anythingllm/docker-compose.yml up -d
fi

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

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

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

cat > /etc/nginx/sites-available/anythingllm <<NGINX
upstream anythingllm_backend {
    server 127.0.0.1:3001;
    keepalive 32;
}

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

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

    client_max_body_size 500M;
    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://anythingllm_backend;
    }
}
NGINX

ln -sf /etc/nginx/sites-available/anythingllm /etc/nginx/sites-enabled/anythingllm
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 "${ANYTHINGLLM_EMAIL}" -d "${ANYTHINGLLM_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|3001|5432|6333)\b' || true

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

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

echo
echo "Multi-user check (expect 401 without bearer):"
curl -sS -o /dev/null -w '%{http_code}\n' "https://${ANYTHINGLLM_DOMAIN}/api/system/check-token" || true

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

echo
echo "Vector store: ${VECTOR_DB}"
if [[ "${VECTOR_DB}" == "qdrant" ]]; then
  echo "  Qdrant API key:"
  echo "  ${ANYTHINGLLM_QDRANT_API_KEY}"
  echo "  Snapshots: /var/lib/qdrant/snapshots"
else
  echo "  LanceDB on persistent volume: /opt/anythingllm/storage/lancedb"
  echo "  Make sure VM-level backup covers /opt/anythingllm/storage."
fi

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

echo
echo "First steps:"
echo "1. Open the URL — the first sign-up becomes the admin account."
echo "2. Settings -> Users -> Invite team members. One workspace per data-scoping boundary."
echo "3. Settings -> LLM Preference -> configure provider (OpenAI / Anthropic / local Ollama)."
echo "4. Upload first documents to a workspace; confirm retrieval is scoped to that workspace only."

Make it executable and run it:

chmod 700 /root/setup-anythingllm-ubuntu22.sh
ANYTHINGLLM_DOMAIN=chat.example.com \
ANYTHINGLLM_EMAIL=ops@example.com \
VECTOR_DB=lancedb \
/root/setup-anythingllm-ubuntu22.sh

The first user that signs up at https://chat.example.com/ becomes the admin — pick that account up immediately, invite the rest of the team, and create one workspace per data-scoping boundary (Ops, Contracts, HR). Documents uploaded to a workspace stay scoped to that workspace; cross-workspace queries are not silently allowed. If you set VECTOR_DB=qdrant instead, the script attaches a Qdrant sidecar bound to the compose network with its own API key and snapshot directory under /var/lib/qdrant. Move /opt/anythingllm/.env into your secrets manager and confirm your VM-level backup covers /opt/anythingllm/storage — that volume holds documents, the LanceDB index, and the Postgres dump path.

Run the production AnythingLLM on Stack Harbor’s managed cloud compute with patching, monitoring, and Sev-1 escalation in place: Cloud compute — or start the conversation if you’d like us to plan the migration.