How to install Margin on a Cloud VPS
Updated 11/11/2026
Margin is an open-source documentation framework that turns a folder of Markdown or MDX files into a searchable docs site served to people and AI agents alike, with llms.txt, an MCP server and Markdown and PDF versions of every page.
Self-hosting your development tools keeps code and project data inside your infrastructure, and the cost does not grow with the number of users.
One-click install on cloudlinux.ro
The fastest way: Margin installs automatically at the first boot of a new server.
- Create a Cloud VPS from the control panel.
- In the configuration step, pick Margin from the app catalog.
- Start the server. The install runs in the background for a few minutes and its status shows on the server page.
- Access details and generated passwords are saved on the server in
/root/app-credentials.txt.
Manual install on any Ubuntu server
If you prefer doing it yourself, below is the exact script our automatic install runs. Execute it as root on a fresh Ubuntu server (24.04 recommended). It stops at the first error, and when it finishes you will find the access details in /root/app-credentials.txt.
export DEBIAN_FRONTEND=noninteractive
cl_firewall
curl -fsSL https://get.docker.com | sh
apt-get install -y git unzip ca-certificates
# Node 24 runs the built server; Bun runs the build, the migrations and the docs ingest.
curl -fsSL https://deb.nodesource.com/setup_24.x | bash -
apt-get install -y nodejs
curl -fsSL https://bun.sh/install | bash
export BUN_INSTALL=/root/.bun
export PATH="$BUN_INSTALL/bin:$PATH"
# The build wants more memory than the small plans carry.
if [ "$(free -m | awk '/Mem:/{print $2}')" -lt 3900 ] && [ ! -f /swapfile ]; then
fallocate -l 2G /swapfile && chmod 600 /swapfile && mkswap /swapfile && swapon /swapfile
echo '/swapfile none swap sw 0 0' >> /etc/fstab
fi
DB_PASS=$(openssl rand -base64 24 | tr -dc 'A-Za-z0-9' | cut -c1-20)
docker volume create margin_db
docker run -d --name margin-db --restart=always -p 127.0.0.1:5432:5432 \
-e POSTGRES_USER=margin -e POSTGRES_PASSWORD="$DB_PASS" -e POSTGRES_DB=margin \
-v margin_db:/var/lib/postgresql/data postgres:17
for i in $(seq 1 30); do docker exec margin-db pg_isready -U margin -d margin >/dev/null 2>&1 && break; sleep 2; done
git clone --depth 1 https://github.com/maniculehq/margin /opt/margin
# The customer's documentation lives outside the code, so updates never touch it.
mkdir -p /srv/docs
cp -r /opt/margin/docs/. /srv/docs/
cat > /etc/margin.env <<ENV
DATABASE_URL=postgres://margin:${DB_PASS}@127.0.0.1:5432/margin
SITE_ORIGIN=https://${CL_HOSTNAME}
DOCS_DIR=/srv/docs
NITRO_PRESET=node-server
NODE_ENV=production
NITRO_HOST=127.0.0.1
PORT=3000
ENV
chmod 600 /etc/margin.env
# Build, migrate and ingest, then restart: the same command republishes after any change in /srv/docs.
# The content key is a hash of the docs folder, so edits are picked up even without a git commit.
cat > /usr/local/bin/margin-rebuild <<'SH'
#!/bin/bash
set -e
set -a; . /etc/margin.env; set +a
export PATH="/root/.bun/bin:$PATH"
DOCS_CONTENT_SHA=$(find "$DOCS_DIR" -type f -exec sha256sum {} + | sort | sha256sum | cut -c1-40)
export DOCS_CONTENT_SHA
cd /opt/margin
bun install --frozen-lockfile
bun run vercel-build
systemctl restart margin 2>/dev/null || true
SH
chmod +x /usr/local/bin/margin-rebuild
cat > /etc/systemd/system/margin.service <<'UNIT'
[Unit]
Description=Margin documentation site
After=network.target docker.service
[Service]
EnvironmentFile=/etc/margin.env
WorkingDirectory=/opt/margin
ExecStart=/usr/bin/node .output/server/index.mjs
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
UNIT
/usr/local/bin/margin-rebuild
systemctl daemon-reload
systemctl enable --now margin
# The server must answer before we report success.
for i in $(seq 1 30); do curl -fs -o /dev/null -H "Host: $CL_HOSTNAME" -H 'X-Forwarded-Proto: https' http://127.0.0.1:3000/llms.txt && break; sleep 3; done
curl -fs -o /dev/null -H "Host: $CL_HOSTNAME" -H 'X-Forwarded-Proto: https' http://127.0.0.1:3000/llms.txt
cl_expose Margin 3000
{
printf 'Documentatia ta: pune fisierele Markdown sau MDX in /srv/docs (acum contine documentatia Margin, ca exemplu), apoi ruleaza: margin-rebuild\n'
printf 'Index pentru agenti AI: https://%s/llms.txt ; serverul MCP este inclus in aplicatie.\n' "$CL_HOSTNAME"
printf 'Domeniu propriu: schimba SITE_ORIGIN in /etc/margin.env si hostul din /etc/caddy/Caddyfile, apoi margin-rebuild si systemctl restart caddy.\n'
printf 'Baza de date: PostgreSQL in containerul margin-db, baza margin, utilizator margin, parola %s\n' "$DB_PASS"
} >> /root/app-credentials.txt
You can also save this script as a recipe in your account and reuse it on any new server.
Put this guide into practice on your own VPS
EU cloud servers, billed hourly, ready in minutes, with one-click installs for dozens of apps.
See pricingRelated tutorials
How to install Memos on a Cloud VPS
Complete Memos guide: one-click install on cloudlinux.ro or manual setup on any Ubuntu server, step by step.
Updated 11/29/2026ApplicationsHow to install Open Notebook on a Cloud VPS
Complete Open Notebook guide: one-click install on cloudlinux.ro or manual setup on any Ubuntu server, step by step.
Updated 11/29/2026ApplicationsHow to install Pocket ID on a Cloud VPS
Complete Pocket ID guide: one-click install on cloudlinux.ro or manual setup on any Ubuntu server, step by step.
Updated 11/29/2026