API ReferenceREST /api/v1Sign in

OVH + HestiaCP runbook — Kiwi Host

This is the operator how-to. The old checkbox list was not enough. Follow these steps in order. Do not skip the “why this box” section.

Normative product rules stay in mch.md. Customer screens must never name OVH or Hestia.

What you are installing

**Hestia Control Panel** is the free, open-source panel that plays the same role as cPanel: users, packages (disk/inodes), domains, Let’s Encrypt, databases, FTP, file manager, and a web UI on port **8083**.

Kiwi Host’s v1 hosting node **must** be Hestia (mch.md §2.1 / §8). Do not install cPanel (paid), CyberPanel, aaPanel, CloudPanel, or Plesk on the node you will later attach to the control plane. Those would force a second panel adapter.

Kiwi Host itself is **not** PHP. It is Node 22 (Nest API + three Next apps + worker + scheduler) plus **PostgreSQL 16** and **Redis 7**. Hestia can own nginx, SSL, and the customer PHP sites. Postgres and Redis sit beside Hestia on localhost.

Two machines (do not mix them)

| Machine | Role | Panel | | --- | --- | --- | | **Any existing VPS that already serves live sites** | Leave it alone. | Existing nginx (or similar). **Do not install Hestia here.** Hestia replaces nginx/Apache/MySQL and will take down every site on that box. | | **New OVH instance** (this runbook) | Either (A) first **customer hosting node**, or (B) a clean box that also runs the Kiwi **control plane** behind Hestia nginx. | Fresh Ubuntu 24.04 + HestiaCP. |

If you only want a panel like cPanel for customer websites: create the **new** instance and stop after Part 4.

If you also want www / portal / admin on the internet: continue through Part 6 on **that same new instance** (or put the control plane on a **different** existing nginx box — Part 7 — and keep Hestia only for customer sites).

Recommended first go-live:

1. New OVH VPS + Hestia = customer hosting node (like a cPanel server). 2. Control plane (API, portal, www, admin) on the **new** VPS behind Hestia proxy templates, **or** on a separate unused box. Do not reuse a VPS that already hosts other production sites.

---

# Part 1 — Create a clean Ubuntu 24.04 server at OVH

1.1 Open Public Cloud

1. Sign in at OVHcloud Control Panel. 2. Open **Public Cloud** (not “Bare Metal” unless you already know you want a dedicated). 3. Pick or create a **project**. Use a project you are willing to delete if the first install goes wrong (sandbox).

1.2 SSH key

1. In the project: **Project Management** → **SSH Keys**. 2. Add your laptop public key (ssh-ed25519 …). 3. Name it something like ops-laptop. You will select this on create.

1.3 Create the instance

1. **Compute** → **Instances** → **Create an instance**. 2. **Image:** Ubuntu **24.04 LTS** (not 22.04, not Windows, not a “cPanel” marketplace image). 3. **Region:** closest to customers (for NZ/AU typically Sydney / Singapore — pick one and keep using it). 4. **Flavour:** at least **4 vCPU / 8 GB RAM / 80 GB disk**. Hestia + Postgres + Redis + Node will OOM on a 2 GB VPS. 5. **Network:** public IPv4. Add IPv6 if the region offers it. 6. **Login:** user ubuntu (or debian) with the SSH key from 1.2. Disable password login if the wizard offers it. 7. Create. Wait until status is **Active**. 8. Copy the **public IPv4**. Call it NODE_IP in the rest of this doc.

1.4 Firewall (OVH Network Security Group)

Inbound allow only:

| Port | Who | Why | | --- | --- | --- | | 22 | Your office/home IP, not 0.0.0.0/0 if you can avoid it | SSH | | 80 | Anyone | HTTP → HTTPS redirect and ACME | | 443 | Anyone | Sites | | 8083 | **Your IP only** at first | Hestia UI (cPanel equivalent). Later: Kiwi control-plane NAT only (mch.md §8.2). |

Do **not** open 3306, 5432, 6379, 3000–3003, or 25 inbound.

Outbound: leave default for now. Later, block port **25 outbound** on hosting nodes so a hacked WordPress cannot spam (mch.md §12.4). Do that after you confirm you are not sending mail from this box (v1 does not host mailboxes).

1.5 First SSH

From your laptop:

``bash ssh ubuntu@NODE_IP ``

Then:

``bash sudo apt update sudo apt -y upgrade sudo hostnamectl set-hostname panel.YOUR_DOMAIN ``

Replace YOUR_DOMAIN with a domain **you** control (the brand hostname, not a customer shop). Example shape: panel.example.co.nz.

``bash echo "NODE_IP panel.YOUR_DOMAIN" | sudo tee -a /etc/hosts ``

Reboot if the kernel upgraded: sudo reboot. SSH back in.

1.6 DNS for the panel hostname

At the registrar or DNS host for YOUR_DOMAIN (not inside Kiwi Host yet):

| Type | Name | Value | | --- | --- | --- | | A | panel | NODE_IP |

Wait until this works from your laptop:

``bash dig +short panel.YOUR_DOMAIN # must print NODE_IP ``

Let’s Encrypt will fail if this is wrong.

---

# Part 2 — Install HestiaCP (the free cPanel)

Official docs: Hestia getting started.

2.1 Preconditions

- Fresh Ubuntu 24.04. **No** nginx, Apache, MySQL, or ProFTPD already installed. - You are ubuntu with sudo. - Hostname is an FQDN (panel.YOUR_DOMAIN).

2.2 Download the installer

``bash cd /tmp wget https://raw.githubusercontent.com/hestiacp/hestiacp/release/install/hst-install.sh less hst-install.sh # skim; do not pipe unknown scripts without reading ``

2.3 Choose installer flags (match Kiwi Host)

We want nginx + PHP-FPM (customer WordPress later), MariaDB (Hestia default for PHP sites), **PostgreSQL** (Kiwi control plane), FTP, firewall, Fail2ban, API.

We do **not** want a mail stack on the web node (no Exim/Dovecot). We do **not** want BIND if you will use platform DNS (Cloudflare) later.

Generate a long admin password and store it in your password manager **before** you run install:

``bash openssl rand -base64 24 ``

Run (edit email, hostname, password):

``bash sudo bash hst-install.sh \ --interactive no \ --force \ --email "you@YOUR_DOMAIN" \ --hostname "panel.YOUR_DOMAIN" \ --password 'PASTE_THE_GENERATED_PASSWORD' \ --lang en \ --port 8083 \ --apache no \ --phpfpm yes \ --multiphp yes \ --vsftpd yes \ --proftpd no \ --named no \ --mysql yes \ --postgresql yes \ --exim no \ --dovecot no \ --sieve no \ --clamav no \ --spamassassin no \ --iptables yes \ --fail2ban yes \ --quota yes \ --api yes ``

If a flag is rejected, run sudo bash hst-install.sh --help and map to the current names. Do not add --apache yes (we want nginx only).

Install takes 10–20 minutes. The script prints the admin URL:

https://panel.YOUR_DOMAIN:8083

2.4 First login (this is the cPanel moment)

1. Open https://panel.YOUR_DOMAIN:8083 from the IP you allowed in the firewall. 2. User: admin 3. Password: the one you passed to the installer. 4. Browser will warn if the cert is still self-signed. After step 2.5 it should be Let’s Encrypt. 5. **Server settings** → set timezone **UTC**. 6. Enable **2FA** for admin (Hestia: user → Two-factor). Save the TOTP seed offline. 7. **Server** → **Configure** → **API**: leave API on. You will later put the API key in Kiwi secrets, not in git. 8. Change the SSH user so you are not living as root. Hestia creates admin for the panel; keep using ubuntu for OS work.

2.5 Let’s Encrypt for the panel itself

In Hestia: **Server** → **SSL** (or Web → panel.YOUR_DOMAIN if the installer created it) → enable Let’s Encrypt for panel.YOUR_DOMAIN.

If there is no web domain yet:

1. **Web** → **Add Web Domain** → panel.YOUR_DOMAIN 2. Enable SSL → Let’s Encrypt 3. Wait for green.

2.6 Create a “package” (cPanel packages)

**Packages** → **Add Package**. Example for a shared plan:

- Disk: 10240 MB - Bandwidth: unlimited or a high cap - Web domains: 10 - Databases: 10 - FTP: 5 - Cron: 5 - Backups: 3

Name it after the **plan code you sell** (e.g. linux-10g), not after a cloud vendor.

You will attach this package to each Hestia **user** (one user ≈ one customer hosting account). Kiwi Host will eventually call the Hestia API to do this; for the first node you do it by hand to prove the box.

---

# Part 3 — Use Hestia like cPanel (customer site smoke test)

Do this once so you know the node works **before** wiring Kiwi Host.

1. **Users** → **Add User** - Username: short, not the domain. Later Kiwi uses u + base36 (mch.md §8.3). For this test: usmoke01 - Package: the package from 2.6 - Email: yours 2. Log in as usmoke01 (or impersonate from admin). 3. **Web** → **Add Web Domain** → a subdomain you control, e.g. smoke.YOUR_DOMAIN 4. DNS: A record smoke → NODE_IP 5. Enable **Let’s Encrypt** 6. Upload a index.html in File Manager (public_html) or drop WordPress later 7. Open https://smoke.YOUR_DOMAIN — you should see the file

If this fails, fix Hestia/DNS/firewall before touching Node.

**Databases (PHP sites):** user → **DB** → Add. That is MariaDB for WordPress. It is **not** the Kiwi Host Postgres database.

---

# Part 4 — OS extras Hestia does not give you

SSH as ubuntu.

4.1 Node.js 22 and pnpm

``bash curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash - sudo apt -y install nodejs git sudo corepack enable corepack prepare pnpm@9.12.0 --activate node -v # v22.x pnpm -v ``

4.2 Redis 7 (queue + cache)

``bash sudo apt -y install redis-server sudo sed -i 's/^bind .*/bind 127.0.0.1 ::1/' /etc/redis/redis.conf # confirm appendonly if you want persistence sudo systemctl enable --now redis-server redis-cli ping # PONG ``

Use DB 0 for cache (REDIS_URL) and DB 1 for BullMQ (REDIS_QUEUE_URL).

4.3 PostgreSQL for Kiwi Host

Hestia’s --postgresql yes installs Postgres, but the **app role** must not own migrations.

``bash sudo -u postgres psql -c "CREATE DATABASE hosting;" sudo -u postgres psql -c "CREATE USER hosting_migrate WITH LOGIN PASSWORD 'GENERATE_MIGRATE_SECRET' SUPERUSER;" # SUPERUSER only if you must for Prisma; prefer CREATEDB + grant. Tightest: run migrate as postgres, app as hosting_app. sudo -u postgres psql -c "CREATE USER hosting_app WITH LOGIN PASSWORD 'GENERATE_APP_SECRET' NOSUPERUSER NOCREATEDB NOCREATEROLE;" sudo -u postgres psql -d hosting -c "GRANT CONNECT ON DATABASE hosting TO hosting_app;" sudo -u postgres psql -d hosting -c "GRANT USAGE ON SCHEMA public TO hosting_app;" sudo -u postgres psql -d hosting -c "ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO hosting_app;" sudo -u postgres psql -d hosting -c "ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT USAGE, SELECT ON SEQUENCES TO hosting_app;" ``

pg_hba.conf: hosting_app and migrate only from 127.0.0.1. Reload: sudo systemctl reload postgresql.

Confirm nothing listens publicly:

``bash ss -lntp | grep -E '5432|6379|3001' # 5432/6379 should be 127.0.0.1 only ``

4.4 Hestia API key (for later Kiwi adapter)

1. Panel as admin → user **Access Keys** / API (wording varies by Hestia version). 2. Create a key with rights to create users, web domains, DB, FTP, SSL. 3. Store it in a secrets file on the **control plane** host, mode 0600. Never commit it. Never return it from /api/v1. 4. Firewall 8083: only the control-plane IP (and you).

---

# Part 5 — Put Kiwi Host behind Hestia (optional, same new VPS)

Only if this new VPS should also serve www / portal / admin.

5.1 Hestia user for the product (not a customer)

Create user kiwihost with a large package (disk for node_modules and builds). Do not reuse usmoke01.

Add **four web domains** (replace with names you registered):

| Hestia web domain | App | Local port | | --- | --- | --- | | www.YOUR_DOMAIN | Next www | 3003 | | portal.YOUR_DOMAIN | Next portal | 3002 | | admin.YOUR_DOMAIN | Next admin | 3000 | | (no public API host) | Nest API | 3001 on localhost only |

DNS A records for www, portal, admin → NODE_IP. Enable Let’s Encrypt on each.

Portal and admin must proxy /api/v1 to 127.0.0.1:3001 (same-origin cookies). Do **not** put the API on a third-party hostname without rewriting cookie Domain.

5.2 Nginx proxy template in Hestia

Hestia document root will be /home/kiwihost/web/portal.YOUR_DOMAIN/public_html. For Next you do **not** serve that folder as PHP. Replace the domain’s nginx config with a reverse proxy.

Hestia path (typical):

/home/kiwihost/conf/web/portal.YOUR_DOMAIN/nginx.conf

or custom template under /usr/local/hestia/data/templates/web/nginx/.

**Portal example** (repeat for admin/www with their ports). Keep Hestia’s SSL files (ssl_certificate paths Hestia already wrote):

```nginx location /api/v1/ { proxy_pass http://127.0.0.1:3001/api/v1/; proxy_http_version 1.1; 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; }

location / { proxy_pass http://127.0.0.1:3002; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $host; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Real-IP $remote_addr; } ```

www: proxy_pass http://127.0.0.1:3003 and **no** /api/v1 unless you need it.

admin: proxy_pass http://127.0.0.1:3000 plus the same /api/v1 block.

After edits:

``bash sudo nginx -t sudo v-restart-web ``

Hestia may overwrite custom nginx on “rebuild”. Put the proxy in a **custom Hestia nginx template** named e.g. node-proxy and assign that template on the domain in the UI (Web → Edit → Nginx template). Re-apply after every Hestia upgrade.

5.3 Application files

``bash sudo mkdir -p /var/www/kiwi-hosting sudo chown ubuntu:ubuntu /var/www/kiwi-hosting # clone your git remote (not a customer shop URL) git clone git@github.com:YOUR_ORG/kiwi-hosting.git /var/www/kiwi-hosting cd /var/www/kiwi-hosting pnpm install --frozen-lockfile cp .env.example .env chmod 600 .env ``

Edit .env (production values, **new** secrets — not the laptop file):

``` NODE_ENV=production API_PORT=3001 API_PUBLIC_URL=https://portal.YOUR_DOMAIN ADMIN_ORIGIN=https://admin.YOUR_DOMAIN PORTAL_ORIGIN=https://portal.YOUR_DOMAIN WWW_ORIGIN=https://www.YOUR_DOMAIN

DATABASE_URL=postgresql://hosting_app:APP_SECRET@127.0.0.1:5432/hosting DATABASE_URL_MIGRATE=postgresql://hosting_migrate:MIGRATE_SECRET@127.0.0.1:5432/hosting

REDIS_URL=redis://127.0.0.1:6379/0 REDIS_QUEUE_URL=redis://127.0.0.1:6379/1

BETTER_AUTH_SECRET= # openssl rand -base64 48 APP_ENCRYPTION_KEY= # 64 hex chars ```

Fill Stripe (test until you sell), seller GST lines, optional DNS token. **Do not** copy demo@local.test to this host.

``bash pnpm --filter @hosting/db prisma:migrate pnpm build ``

5.4 systemd (Hestia does not keep Node running)

Create /etc/systemd/system/kiwi-api.service:

```ini [Unit] Description=Kiwi Host API After=network.target postgresql.service redis-server.service

[Service] Type=simple User=ubuntu WorkingDirectory=/var/www/kiwi-hosting EnvironmentFile=/var/www/kiwi-hosting/.env ExecStart=/usr/bin/pnpm --filter @hosting/api start # After pnpm build, this runs node dist/main.js in apps/api. Portal/admin/www: pnpm --filter @hosting/portal start (port 3002), @hosting/admin (3000), @hosting/www (3003). Restart=on-failure RestartSec=5

[Install] WantedBy=multi-user.target ```

If start is not defined on the API package, use the same command you use in production locally (node on the built dist). Check apps/api/package.json scripts.start.

Clone the unit for:

- kiwi-portal — pnpm --filter @hosting/portal start (Next, port 3002) - kiwi-admin — pnpm --filter @hosting/admin start (port 3000) - kiwi-www — pnpm --filter @hosting/www start (port 3003) - kiwi-worker — node apps/worker/dist/main.js (no start script yet; WorkingDirectory still repo root; load EnvironmentFile) - kiwi-scheduler — node apps/scheduler/dist/main.js

ExecStart for API must run after pnpm build so apps/api/dist/main.js exists. Next apps need pnpm build in each app too.

``bash sudo systemctl daemon-reload sudo systemctl enable --now kiwi-api kiwi-portal kiwi-admin kiwi-www kiwi-worker kiwi-scheduler sudo systemctl status kiwi-api curl -sS http://127.0.0.1:3001/health ``

Then hit https://www.YOUR_DOMAIN and https://portal.YOUR_DOMAIN/signin in the browser.

Create a **real** staff user and a **real** customer. Do not seed the laptop demo on a public hostname.

---

# Part 6 — What Hestia will do later (when Kiwi Host calls it)

You do not need this on day one. This is how the panel maps to cPanel habits:

| cPanel | Hestia | Kiwi Host | | --- | --- | --- | | Reseller / package | Package | plans / plan_limits | | cPanel account | User | hosting_accounts.panel_username | | Addon domain | Web domain | domains | | MySQL DB | Hestia DB | databases (customer PHP) | | FTP | FTP | ftp_users | | AutoSSL | Let’s Encrypt on the domain | ssl_certificates (renewal **on the node**, mch.md §13.4) |

The control plane must create those via **jobs** and the Hestia adapter, never from a Nest controller calling OVH or Hestia inline (mch.md §11).

Until the adapter is live, you may create test users **only** in the Hestia UI.

---

# Part 7 — Control plane on a separate existing nginx box (optional)

Only if you already have a **different** Ubuntu host with nginx that is **not** the Hestia node, and you accept the extra ops cost. Allowed: extra nginx server blocks for portal / www / admin, Node + Postgres + Redis **on localhost**, no Hestia.

Forbidden: hst-install.sh on that host.

Steps in short:

1. SSH to that host (whatever IP OVH issued — do not copy an old address from notes). 2. Record existing vhosts: ls /etc/nginx/sites-enabled (or the layout this box already uses). 3. Add **new** server names only. Do not edit unrelated site files. 4. Follow 4.1–4.3 and 5.3–5.4 on this host, but skip Hestia templates; write nginx vhosts in the **existing** style of that server. 5. Put Hestia on the **new** OVH instance (Parts 1–3) when you want cPanel-like customer hosting.

---

# Part 8 — Verify and stop

Control plane (if deployed):

- https://www.YOUR_DOMAIN loads. - https://portal.YOUR_DOMAIN/signin loads. - curl -sS https://portal.YOUR_DOMAIN/api/v1/health or local 3001/health. - Existing sites on any **non-Hestia** box you left alone still load.

Hestia node:

- https://panel.YOUR_DOMAIN:8083 from your IP only. - https://smoke.YOUR_DOMAIN still loads. - ss -lntp shows 5432/6379/3001 bound to localhost.

Do not

- Install Hestia on a VPS that already has production nginx sites. - Open Postgres, Redis, or Node ports to the world. - Put laptop .env or demo@local.test on a public host. - Name OVH or Hestia on invoices, portal DNS copy, or tickets. - Call OVH or Hestia from an HTTP controller; enqueue a job.

When something fails

| Symptom | Likely cause | | --- | --- | | Let’s Encrypt error | A record not pointing at NODE_IP, or port 80 blocked | | 8083 timeout | OVH security group, or Hestia iptables | | Sites 502 | Node systemd unit down; journalctl -u kiwi-portal -n 80 | | Portal signed out immediately | /api/v1 not same-origin; cookie Secure/HTTPS mismatch | | Hestia wiped your proxy | Domain rebuilt; re-apply nginx template | | Existing production sites died | Hestia or a default nginx was installed on a box that already had live vhosts — restore from backup, do not continue |

---

# Order of work (one sitting)

1. Part 1 — new Ubuntu 24.04 at OVH, SSH, firewall, panel A record. 2. Part 2 — Hestia install, 2FA, Let’s Encrypt, one package. 3. Part 3 — smoke user + https://smoke.YOUR_DOMAIN. 4. Part 4 — Node, Redis, Postgres, API key in a secrets file. 5. Either Part 5 (control plane on this VPS) or Part 7 (control plane on a **separate** existing nginx box — not a multi-site production VPS you already run). 6. Part 8 — verify. Stop. Do not start the live OVH **compute** adapter until this node is boringly stable.

Markdown source
# OVH + HestiaCP runbook — Kiwi Host

This is the operator how-to. The old checkbox list was not enough. Follow these steps in order. Do not skip the “why this box” section.

Normative product rules stay in `mch.md`. Customer screens must never name OVH or Hestia.

## What you are installing

**Hestia Control Panel** is the free, open-source panel that plays the same role as cPanel: users, packages (disk/inodes), domains, Let’s Encrypt, databases, FTP, file manager, and a web UI on port **8083**.

Kiwi Host’s v1 hosting node **must** be Hestia (`mch.md` §2.1 / §8). Do not install cPanel (paid), CyberPanel, aaPanel, CloudPanel, or Plesk on the node you will later attach to the control plane. Those would force a second panel adapter.

Kiwi Host itself is **not** PHP. It is Node 22 (Nest API + three Next apps + worker + scheduler) plus **PostgreSQL 16** and **Redis 7**. Hestia can own nginx, SSL, and the customer PHP sites. Postgres and Redis sit beside Hestia on localhost.

## Two machines (do not mix them)

| Machine | Role | Panel |
| --- | --- | --- |
| **Any existing VPS that already serves live sites** | Leave it alone. | Existing nginx (or similar). **Do not install Hestia here.** Hestia replaces nginx/Apache/MySQL and will take down every site on that box. |
| **New OVH instance** (this runbook) | Either (A) first **customer hosting node**, or (B) a clean box that also runs the Kiwi **control plane** behind Hestia nginx. | Fresh Ubuntu 24.04 + HestiaCP. |

If you only want a panel like cPanel for customer websites: create the **new** instance and stop after Part 4.

If you also want www / portal / admin on the internet: continue through Part 6 on **that same new instance** (or put the control plane on a **different** existing nginx box — Part 7 — and keep Hestia only for customer sites).

Recommended first go-live:

1. New OVH VPS + Hestia = customer hosting node (like a cPanel server).
2. Control plane (API, portal, www, admin) on the **new** VPS behind Hestia proxy templates, **or** on a separate unused box. Do not reuse a VPS that already hosts other production sites.

---

# Part 1 — Create a clean Ubuntu 24.04 server at OVH

## 1.1 Open Public Cloud

1. Sign in at [OVHcloud Control Panel](https://www.ovh.com/manager/).
2. Open **Public Cloud** (not “Bare Metal” unless you already know you want a dedicated).
3. Pick or create a **project**. Use a project you are willing to delete if the first install goes wrong (sandbox).

## 1.2 SSH key

1. In the project: **Project Management** → **SSH Keys**.
2. Add your laptop public key (`ssh-ed25519 …`).
3. Name it something like `ops-laptop`. You will select this on create.

## 1.3 Create the instance

1. **Compute** → **Instances** → **Create an instance**.
2. **Image:** Ubuntu **24.04 LTS** (not 22.04, not Windows, not a “cPanel” marketplace image).
3. **Region:** closest to customers (for NZ/AU typically Sydney / Singapore — pick one and keep using it).
4. **Flavour:** at least **4 vCPU / 8 GB RAM / 80 GB disk**. Hestia + Postgres + Redis + Node will OOM on a 2 GB VPS.
5. **Network:** public IPv4. Add IPv6 if the region offers it.
6. **Login:** user `ubuntu` (or `debian`) with the SSH key from 1.2. Disable password login if the wizard offers it.
7. Create. Wait until status is **Active**.
8. Copy the **public IPv4**. Call it `NODE_IP` in the rest of this doc.

## 1.4 Firewall (OVH Network Security Group)

Inbound allow only:

| Port | Who | Why |
| --- | --- | --- |
| 22 | Your office/home IP, not `0.0.0.0/0` if you can avoid it | SSH |
| 80 | Anyone | HTTP → HTTPS redirect and ACME |
| 443 | Anyone | Sites |
| 8083 | **Your IP only** at first | Hestia UI (cPanel equivalent). Later: Kiwi control-plane NAT only (`mch.md` §8.2). |

Do **not** open 3306, 5432, 6379, 3000–3003, or 25 inbound.

Outbound: leave default for now. Later, block port **25 outbound** on hosting nodes so a hacked WordPress cannot spam (`mch.md` §12.4). Do that after you confirm you are not sending mail from this box (v1 does not host mailboxes).

## 1.5 First SSH

From your laptop:

```bash
ssh ubuntu@NODE_IP
```

Then:

```bash
sudo apt update
sudo apt -y upgrade
sudo hostnamectl set-hostname panel.YOUR_DOMAIN
```

Replace `YOUR_DOMAIN` with a domain **you** control (the brand hostname, not a customer shop). Example shape: `panel.example.co.nz`.

```bash
echo "NODE_IP  panel.YOUR_DOMAIN" | sudo tee -a /etc/hosts
```

Reboot if the kernel upgraded: `sudo reboot`. SSH back in.

## 1.6 DNS for the panel hostname

At the registrar or DNS host for `YOUR_DOMAIN` (not inside Kiwi Host yet):

| Type | Name | Value |
| --- | --- | --- |
| A | `panel` | `NODE_IP` |

Wait until this works from your laptop:

```bash
dig +short panel.YOUR_DOMAIN
# must print NODE_IP
```

Let’s Encrypt will fail if this is wrong.

---

# Part 2 — Install HestiaCP (the free cPanel)

Official docs: [Hestia getting started](https://hestiacp.com/docs/introduction/getting-started.html).

## 2.1 Preconditions

- Fresh Ubuntu 24.04. **No** nginx, Apache, MySQL, or ProFTPD already installed.
- You are `ubuntu` with sudo.
- Hostname is an FQDN (`panel.YOUR_DOMAIN`).

## 2.2 Download the installer

```bash
cd /tmp
wget https://raw.githubusercontent.com/hestiacp/hestiacp/release/install/hst-install.sh
less hst-install.sh   # skim; do not pipe unknown scripts without reading
```

## 2.3 Choose installer flags (match Kiwi Host)

We want nginx + PHP-FPM (customer WordPress later), MariaDB (Hestia default for PHP sites), **PostgreSQL** (Kiwi control plane), FTP, firewall, Fail2ban, API.

We do **not** want a mail stack on the web node (no Exim/Dovecot). We do **not** want BIND if you will use platform DNS (Cloudflare) later.

Generate a long admin password and store it in your password manager **before** you run install:

```bash
openssl rand -base64 24
```

Run (edit email, hostname, password):

```bash
sudo bash hst-install.sh \
  --interactive no \
  --force \
  --email "you@YOUR_DOMAIN" \
  --hostname "panel.YOUR_DOMAIN" \
  --password 'PASTE_THE_GENERATED_PASSWORD' \
  --lang en \
  --port 8083 \
  --apache no \
  --phpfpm yes \
  --multiphp yes \
  --vsftpd yes \
  --proftpd no \
  --named no \
  --mysql yes \
  --postgresql yes \
  --exim no \
  --dovecot no \
  --sieve no \
  --clamav no \
  --spamassassin no \
  --iptables yes \
  --fail2ban yes \
  --quota yes \
  --api yes
```

If a flag is rejected, run `sudo bash hst-install.sh --help` and map to the current names. Do not add `--apache yes` (we want nginx only).

Install takes 10–20 minutes. The script prints the admin URL:

`https://panel.YOUR_DOMAIN:8083`

## 2.4 First login (this is the cPanel moment)

1. Open `https://panel.YOUR_DOMAIN:8083` from the IP you allowed in the firewall.
2. User: `admin`
3. Password: the one you passed to the installer.
4. Browser will warn if the cert is still self-signed. After step 2.5 it should be Let’s Encrypt.
5. **Server settings** → set timezone **UTC**.
6. Enable **2FA** for `admin` (Hestia: user → Two-factor). Save the TOTP seed offline.
7. **Server** → **Configure** → **API**: leave API on. You will later put the API key in Kiwi secrets, not in git.
8. Change the SSH user so you are not living as `root`. Hestia creates `admin` for the panel; keep using `ubuntu` for OS work.

## 2.5 Let’s Encrypt for the panel itself

In Hestia: **Server** → **SSL** (or Web → `panel.YOUR_DOMAIN` if the installer created it) → enable Let’s Encrypt for `panel.YOUR_DOMAIN`.

If there is no web domain yet:

1. **Web** → **Add Web Domain** → `panel.YOUR_DOMAIN`
2. Enable SSL → Let’s Encrypt
3. Wait for green.

## 2.6 Create a “package” (cPanel packages)

**Packages** → **Add Package**. Example for a shared plan:

- Disk: 10240 MB  
- Bandwidth: unlimited or a high cap  
- Web domains: 10  
- Databases: 10  
- FTP: 5  
- Cron: 5  
- Backups: 3  

Name it after the **plan code you sell** (e.g. `linux-10g`), not after a cloud vendor.

You will attach this package to each Hestia **user** (one user ≈ one customer hosting account). Kiwi Host will eventually call the Hestia API to do this; for the first node you do it by hand to prove the box.

---

# Part 3 — Use Hestia like cPanel (customer site smoke test)

Do this once so you know the node works **before** wiring Kiwi Host.

1. **Users** → **Add User**
   - Username: short, not the domain. Later Kiwi uses `u` + base36 (`mch.md` §8.3). For this test: `usmoke01`
   - Package: the package from 2.6
   - Email: yours
2. Log in as `usmoke01` (or impersonate from admin).
3. **Web** → **Add Web Domain** → a subdomain you control, e.g. `smoke.YOUR_DOMAIN`
4. DNS: A record `smoke` → `NODE_IP`
5. Enable **Let’s Encrypt**
6. Upload a `index.html` in File Manager (`public_html`) or drop WordPress later
7. Open `https://smoke.YOUR_DOMAIN` — you should see the file

If this fails, fix Hestia/DNS/firewall before touching Node.

**Databases (PHP sites):** user → **DB** → Add. That is MariaDB for WordPress. It is **not** the Kiwi Host Postgres database.

---

# Part 4 — OS extras Hestia does not give you

SSH as `ubuntu`.

## 4.1 Node.js 22 and pnpm

```bash
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt -y install nodejs git
sudo corepack enable
corepack prepare pnpm@9.12.0 --activate
node -v   # v22.x
pnpm -v
```

## 4.2 Redis 7 (queue + cache)

```bash
sudo apt -y install redis-server
sudo sed -i 's/^bind .*/bind 127.0.0.1 ::1/' /etc/redis/redis.conf
# confirm appendonly if you want persistence
sudo systemctl enable --now redis-server
redis-cli ping   # PONG
```

Use DB 0 for cache (`REDIS_URL`) and DB 1 for BullMQ (`REDIS_QUEUE_URL`).

## 4.3 PostgreSQL for Kiwi Host

Hestia’s `--postgresql yes` installs Postgres, but the **app role** must not own migrations.

```bash
sudo -u postgres psql -c "CREATE DATABASE hosting;"
sudo -u postgres psql -c "CREATE USER hosting_migrate WITH LOGIN PASSWORD 'GENERATE_MIGRATE_SECRET' SUPERUSER;"
# SUPERUSER only if you must for Prisma; prefer CREATEDB + grant. Tightest: run migrate as postgres, app as hosting_app.
sudo -u postgres psql -c "CREATE USER hosting_app WITH LOGIN PASSWORD 'GENERATE_APP_SECRET' NOSUPERUSER NOCREATEDB NOCREATEROLE;"
sudo -u postgres psql -d hosting -c "GRANT CONNECT ON DATABASE hosting TO hosting_app;"
sudo -u postgres psql -d hosting -c "GRANT USAGE ON SCHEMA public TO hosting_app;"
sudo -u postgres psql -d hosting -c "ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO hosting_app;"
sudo -u postgres psql -d hosting -c "ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT USAGE, SELECT ON SEQUENCES TO hosting_app;"
```

`pg_hba.conf`: `hosting_app` and migrate only from `127.0.0.1`. Reload: `sudo systemctl reload postgresql`.

Confirm nothing listens publicly:

```bash
ss -lntp | grep -E '5432|6379|3001'
# 5432/6379 should be 127.0.0.1 only
```

## 4.4 Hestia API key (for later Kiwi adapter)

1. Panel as `admin` → user **Access Keys** / API (wording varies by Hestia version).
2. Create a key with rights to create users, web domains, DB, FTP, SSL.
3. Store it in a secrets file on the **control plane** host, mode `0600`. Never commit it. Never return it from `/api/v1`.
4. Firewall 8083: only the control-plane IP (and you).

---

# Part 5 — Put Kiwi Host behind Hestia (optional, same new VPS)

Only if this new VPS should also serve www / portal / admin.

## 5.1 Hestia user for the product (not a customer)

Create user `kiwihost` with a large package (disk for `node_modules` and builds). Do not reuse `usmoke01`.

Add **four web domains** (replace with names you registered):

| Hestia web domain | App | Local port |
| --- | --- | --- |
| `www.YOUR_DOMAIN` | Next www | 3003 |
| `portal.YOUR_DOMAIN` | Next portal | 3002 |
| `admin.YOUR_DOMAIN` | Next admin | 3000 |
| (no public API host) | Nest API | 3001 on localhost only |

DNS A records for `www`, `portal`, `admin` → `NODE_IP`. Enable Let’s Encrypt on each.

Portal and admin must proxy `/api/v1` to `127.0.0.1:3001` (same-origin cookies). Do **not** put the API on a third-party hostname without rewriting cookie `Domain`.

## 5.2 Nginx proxy template in Hestia

Hestia document root will be `/home/kiwihost/web/portal.YOUR_DOMAIN/public_html`. For Next you do **not** serve that folder as PHP. Replace the domain’s nginx config with a reverse proxy.

Hestia path (typical):

`/home/kiwihost/conf/web/portal.YOUR_DOMAIN/nginx.conf`

or custom template under `/usr/local/hestia/data/templates/web/nginx/`.

**Portal example** (repeat for admin/www with their ports). Keep Hestia’s SSL files (`ssl_certificate` paths Hestia already wrote):

```nginx
location /api/v1/ {
    proxy_pass http://127.0.0.1:3001/api/v1/;
    proxy_http_version 1.1;
    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;
}

location / {
    proxy_pass http://127.0.0.1:3002;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Real-IP $remote_addr;
}
```

www: `proxy_pass http://127.0.0.1:3003` and **no** `/api/v1` unless you need it.

admin: `proxy_pass http://127.0.0.1:3000` plus the same `/api/v1` block.

After edits:

```bash
sudo nginx -t
sudo v-restart-web
```

Hestia may overwrite custom nginx on “rebuild”. Put the proxy in a **custom Hestia nginx template** named e.g. `node-proxy` and assign that template on the domain in the UI (Web → Edit → Nginx template). Re-apply after every Hestia upgrade.

## 5.3 Application files

```bash
sudo mkdir -p /var/www/kiwi-hosting
sudo chown ubuntu:ubuntu /var/www/kiwi-hosting
# clone your git remote (not a customer shop URL)
git clone git@github.com:YOUR_ORG/kiwi-hosting.git /var/www/kiwi-hosting
cd /var/www/kiwi-hosting
pnpm install --frozen-lockfile
cp .env.example .env
chmod 600 .env
```

Edit `.env` (production values, **new** secrets — not the laptop file):

```
NODE_ENV=production
API_PORT=3001
API_PUBLIC_URL=https://portal.YOUR_DOMAIN
ADMIN_ORIGIN=https://admin.YOUR_DOMAIN
PORTAL_ORIGIN=https://portal.YOUR_DOMAIN
WWW_ORIGIN=https://www.YOUR_DOMAIN

DATABASE_URL=postgresql://hosting_app:APP_SECRET@127.0.0.1:5432/hosting
DATABASE_URL_MIGRATE=postgresql://hosting_migrate:MIGRATE_SECRET@127.0.0.1:5432/hosting

REDIS_URL=redis://127.0.0.1:6379/0
REDIS_QUEUE_URL=redis://127.0.0.1:6379/1

BETTER_AUTH_SECRET=   # openssl rand -base64 48
APP_ENCRYPTION_KEY=   # 64 hex chars
```

Fill Stripe (test until you sell), seller GST lines, optional DNS token. **Do not** copy `demo@local.test` to this host.

```bash
pnpm --filter @hosting/db prisma:migrate
pnpm build
```

## 5.4 systemd (Hestia does not keep Node running)

Create `/etc/systemd/system/kiwi-api.service`:

```ini
[Unit]
Description=Kiwi Host API
After=network.target postgresql.service redis-server.service

[Service]
Type=simple
User=ubuntu
WorkingDirectory=/var/www/kiwi-hosting
EnvironmentFile=/var/www/kiwi-hosting/.env
ExecStart=/usr/bin/pnpm --filter @hosting/api start
# After `pnpm build`, this runs `node dist/main.js` in apps/api. Portal/admin/www: `pnpm --filter @hosting/portal start` (port 3002), `@hosting/admin` (3000), `@hosting/www` (3003).
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target
```

If `start` is not defined on the API package, use the same command you use in production locally (`node` on the built `dist`). Check `apps/api/package.json` `scripts.start`.

Clone the unit for:

- `kiwi-portal` — `pnpm --filter @hosting/portal start` (Next, port 3002)
- `kiwi-admin` — `pnpm --filter @hosting/admin start` (port 3000)
- `kiwi-www` — `pnpm --filter @hosting/www start` (port 3003)
- `kiwi-worker` — `node apps/worker/dist/main.js` (no `start` script yet; `WorkingDirectory` still repo root; load `EnvironmentFile`)
- `kiwi-scheduler` — `node apps/scheduler/dist/main.js`

`ExecStart` for API must run after `pnpm build` so `apps/api/dist/main.js` exists. Next apps need `pnpm build` in each app too.

```bash
sudo systemctl daemon-reload
sudo systemctl enable --now kiwi-api kiwi-portal kiwi-admin kiwi-www kiwi-worker kiwi-scheduler
sudo systemctl status kiwi-api
curl -sS http://127.0.0.1:3001/health
```

Then hit `https://www.YOUR_DOMAIN` and `https://portal.YOUR_DOMAIN/signin` in the browser.

Create a **real** staff user and a **real** customer. Do not seed the laptop demo on a public hostname.

---

# Part 6 — What Hestia will do later (when Kiwi Host calls it)

You do not need this on day one. This is how the panel maps to cPanel habits:

| cPanel | Hestia | Kiwi Host |
| --- | --- | --- |
| Reseller / package | Package | `plans` / `plan_limits` |
| cPanel account | User | `hosting_accounts.panel_username` |
| Addon domain | Web domain | `domains` |
| MySQL DB | Hestia DB | `databases` (customer PHP) |
| FTP | FTP | `ftp_users` |
| AutoSSL | Let’s Encrypt on the domain | `ssl_certificates` (renewal **on the node**, `mch.md` §13.4) |

The control plane must create those via **jobs** and the Hestia adapter, never from a Nest controller calling OVH or Hestia inline (`mch.md` §11).

Until the adapter is live, you may create test users **only** in the Hestia UI.

---

# Part 7 — Control plane on a separate existing nginx box (optional)

Only if you already have a **different** Ubuntu host with nginx that is **not** the Hestia node, and you accept the extra ops cost. Allowed: extra nginx server blocks for `portal` / `www` / `admin`, Node + Postgres + Redis **on localhost**, no Hestia.

Forbidden: `hst-install.sh` on that host.

Steps in short:

1. SSH to that host (whatever IP OVH issued — do not copy an old address from notes).
2. Record existing vhosts: `ls /etc/nginx/sites-enabled` (or the layout this box already uses).
3. Add **new** server names only. Do not edit unrelated site files.
4. Follow 4.1–4.3 and 5.3–5.4 on this host, but skip Hestia templates; write nginx vhosts in the **existing** style of that server.
5. Put Hestia on the **new** OVH instance (Parts 1–3) when you want cPanel-like customer hosting.

---

# Part 8 — Verify and stop

Control plane (if deployed):

- `https://www.YOUR_DOMAIN` loads.
- `https://portal.YOUR_DOMAIN/signin` loads.
- `curl -sS https://portal.YOUR_DOMAIN/api/v1/health` or local `3001/health`.
- Existing sites on any **non-Hestia** box you left alone still load.

Hestia node:

- `https://panel.YOUR_DOMAIN:8083` from your IP only.
- `https://smoke.YOUR_DOMAIN` still loads.
- `ss -lntp` shows 5432/6379/3001 bound to localhost.

## Do not

- Install Hestia on a VPS that already has production nginx sites.
- Open Postgres, Redis, or Node ports to the world.
- Put laptop `.env` or `demo@local.test` on a public host.
- Name OVH or Hestia on invoices, portal DNS copy, or tickets.
- Call OVH or Hestia from an HTTP controller; enqueue a job.

## When something fails

| Symptom | Likely cause |
| --- | --- |
| Let’s Encrypt error | A record not pointing at `NODE_IP`, or port 80 blocked |
| 8083 timeout | OVH security group, or Hestia iptables |
| Sites 502 | Node systemd unit down; `journalctl -u kiwi-portal -n 80` |
| Portal signed out immediately | `/api/v1` not same-origin; cookie Secure/HTTPS mismatch |
| Hestia wiped your proxy | Domain rebuilt; re-apply nginx template |
| Existing production sites died | Hestia or a default nginx was installed on a box that already had live vhosts — restore from backup, do not continue |

---

# Order of work (one sitting)

1. Part 1 — new Ubuntu 24.04 at OVH, SSH, firewall, `panel` A record.  
2. Part 2 — Hestia install, 2FA, Let’s Encrypt, one package.  
3. Part 3 — smoke user + `https://smoke.YOUR_DOMAIN`.  
4. Part 4 — Node, Redis, Postgres, API key in a secrets file.  
5. Either Part 5 (control plane on this VPS) or Part 7 (control plane on a **separate** existing nginx box — not a multi-site production VPS you already run).  
6. Part 8 — verify. Stop. Do not start the live OVH **compute** adapter until this node is boringly stable.