# Bluehost → Hetzner Cloud Migration Guide

**Total time: ~45 minutes**
**Downtime: ~5-10 minutes (DNS propagation doesn't affect email)**

---

## Step 1: Create Hetzner Account (5 min)

1. Go to https://console.hetzner.cloud
2. Sign up with your email
3. Add payment method (Visa/MC)
4. Create a project named "Fogbreak"

---

## Step 2: Create Server (2 min)

**Server specs:**
- **Location:** Ashburn, VA (us-east)
- **Image:** Ubuntu 24.04
- **Type:** CX22 (2 vCPU, 4GB RAM, 40GB SSD) — €4.51/mo
- **Name:** fogbreak-prod

**SSH Key setup:**
1. Check if you have a key: `cat ~/.ssh/id_ed25519.pub`
2. If nothing prints, create one: `ssh-keygen -t ed25519 -C "matthams@gmail.com"`
3. In Hetzner console, add SSH Key, paste your public key
4. Select the key when creating the server

**After creation:** Write down the server's IP address.

---

## Step 3: Point DNS (5 min)

Go to wherever your fogbreak.io DNS is hosted (likely Namecheap or your registrar):

1. Create/update **A record:**
   - `fogbreak.io` → `[server-ip]`
   - `www.fogbreak.io` → `[server-ip]`

2. (Optional) Create **CNAME** for tenant subdomains:
   - `*.fogbreak.io` → `fogbreak.io`

**Note:** DNS takes 5-60 minutes to propagate. The old Bluehost site stays live until it does.

---

## Step 4: Run Setup Script (15 min)

SSH into the server and run one command:

```bash
ssh root@[server-ip]

curl -sSL https://raw.githubusercontent.com/fogbreak-io/fogbreak/main/deploy/setup-server.sh | bash -s -- \
  --domain=fogbreak.io \
  --github-repo=fogbreak-io/fogbreak \
  --email=matthams@gmail.com
```

**What it installs:**
- PHP 8.4 with extensions
- MySQL 8.0
- Nginx with SSL (auto-cert via Let's Encrypt)
- Node.js 22
- Firewall (allow SSH, 80, 443 only)
- Auto-deploy webhook listener

**Output:** The script prints database credentials. Save them.

---

## Step 5: Import Database (10 min)

**On Bluehost (cPanel → phpMyAdmin):**
1. Select `thinkwho_portal` database
2. Export → SQL → Download

**Transfer to Hetzner:**
```bash
scp thinkwho_portal.sql root@[server-ip]:/tmp/
```

**Import on Hetzner:**
```bash
ssh root@[server-ip]

mysql -u fogbreak_app -p fogbreak < /tmp/thinkwho_portal.sql
# Enter password from setup script output
```

---

## Step 6: Configure Secrets (5 min)

```bash
ssh root@[server-ip]

# Edit .env with real values
nano /var/www/fogbreak.io/.env

# Populate:
# DB_HOST, DB_USER, DB_PASS from setup script
# GMAIL_APP_PASSWORD (from Google Account)
# API_KEY (keep existing MTH_PORTAL_2026 or generate new)
# GITHUB_WEBHOOK_SECRET (any random string)
# OPENAI_API_KEY, COLLOV_API_KEY, etc. (leave blank for now)

# Generate config.php from .env
cd /var/www/fogbreak.io/app/api
cp config.php.example config.php
nano config.php  # Fill in actual DB credentials
```

---

## Step 7: Verify (5 min)

```bash
# Test main app
curl https://fogbreak.io/pwa/app/fogbreak.html | head -20

# Test API
curl https://fogbreak.io/pwa/app/api/auth.php?action=ping
# Should return: {"success":true,"message":"API is alive"}

# Visit in browser
# https://fogbreak.io (should load the app)
# https://fogbreak.io/pwa/app/fogbreak.html (should work)
```

If all green, Fogbreak is live on Hetzner.

---

## Step 8: Set Up Auto-Deploy (5 min)

So you never touch the terminal again:

1. Go to GitHub → fogbreak-io/fogbreak → Settings → Webhooks
2. Click "Add webhook"
3. URL: `https://fogbreak.io/pwa/app/deploy/webhook.php`
4. Secret: Use the `GITHUB_WEBHOOK_SECRET` from your .env
5. Events: Push only
6. Active: Yes

Now every `git push` to `main` auto-deploys. No cPanel. No manual uploads.

---

## What to Do With Bluehost

- Keep email hosting (if you're using Bluehost SMTP)
- Keep any other websites on that account
- Once DNS fully propagates & you've verified everything, you can cancel the hosting plan

---

## Scaling Later

**Need more power?** Resize in Hetzner console (2 clicks, ~30 sec downtime).

**Need AI inference?** SSH in and run:
```bash
ollama pull llama3.3:70b
```

**Need global speed?** Add Cloudflare CDN in front (free tier works).

**Need multi-server?** Add a load balancer + multiple app servers (both available in Hetzner).

---

## Cost Breakdown

| | Bluehost | Hetzner CX22 |
|---|---|---|
| Monthly | $13-25 | €4.51 (~$5) |
| PostgreSQL | ❌ | ✅ |
| Node.js | ❌ | ✅ |
| Root SSH | Limited | Full |
| Auto-deploy | ❌ | ✅ |
| Ollama/AI | ❌ | ✅ |
| 1-click scale | ❌ | ✅ |

**Net: 80% cheaper, 5x more capability.**

---

## Rollback Plan

If something breaks after migration:

1. **DNS rollback** (instant): Point A record back to Bluehost IP. Old site lives again.
2. **Database rollback** (5 min): Restore from Bluehost backup, fix, re-import.
3. **Code rollback** (instant): SSH and `cd /var/www/fogbreak.io && git revert [commit-hash] && git push`.

Keep the Bluehost backup for 48 hours after DNS fully switches.

---

**Questions? Check CLAUDE.md → DEPLOYMENT section or ARCHITECTURE.html → Infrastructure.**
