# Deploy ElbeeGems Community to cPanel (`community.elbeegems.com`)

This is a **Node.js** Next.js mockup. It will not run as plain PHP in `public_html`.

You need **cPanel → Setup Node.js App** (or SSH + Node 18+).

## 1. Create the subdomain

In cPanel:

1. **Domains / Subdomains** → `community.elbeegems.com`
2. Note the document root (example: `community.elbeegems.com` or `public_html/community`)

Prefer keeping the Node app **outside** the WordPress root if your host allows it, e.g.:

`/home/YOURUSER/community`

## Fast path: upload a pre-built Linux zip

On your Mac (with Docker running):

```bash
cd app/public/community
npm run build:cpanel
```

That writes `app/public/community-cpanel-built.zip` with `.next` + Linux `node_modules` already inside.

On cPanel:

1. Extract into the Node application root
2. Startup file = `server.js`
3. **Restart** — no `npm run build` on the server

Env is already in `.env` inside the zip (`NEXT_PUBLIC_APP_URL=https://community.elbeegems.com`).

---

## Alternate: source-only zip

From your Mac (in this repo):

```bash
cd app/public/community
chmod +x scripts/pack-cpanel.sh
./scripts/pack-cpanel.sh
```

That writes `app/public/community-cpanel.zip`.

Upload and extract into the Node application root (not mixed into the WordPress theme).

Include `prisma/dev.db` (seeded mock data). Do **not** upload `.env` from your laptop as-is.

## 3. Setup Node.js App (cPanel)

1. Open **Setup Node.js App** → **Create Application**
2. **Node.js version:** 20.x (or 18+)
3. **Application mode:** Production
4. **Application root:** folder where you extracted the zip
5. **Application URL:** `community.elbeegems.com` (or `/` on that subdomain)
6. **Application startup file:** `server.js`
7. Create the app, then open **Environment variables** and set:

| Name | Value |
|------|--------|
| `NODE_ENV` | `production` |
| `DATABASE_URL` | `file:./dev.db` |
| `AUTH_SECRET` | long random string |
| `NEXT_PUBLIC_APP_URL` | `https://community.elbeegems.com` |

Also create a `.env` in the app root with the same values (some hosts only inject UI vars).

## 4. Install and build **on the server**

In the Node app panel, open the terminal / SSH into that folder (Linux build is required — do not copy `node_modules` from a Mac).

```bash
npm ci
npx prisma generate
npm run build
```

Confirm these exist after build:

- `node_modules/`
- `.next/`
- `prisma/dev.db`
- `server.js`

Then **Restart** the Node application in cPanel.

### If you see 503

1. Open **Setup Node.js App** → your app → **Stderr log** (or Error log).
2. Most common cause: build was never run on the server (no `.next` folder).
3. Startup file must be exactly `server.js` (in the application root).
4. Application root must be the folder that contains `package.json` and `server.js`.
5. After fixing, click **Restart**.

Passenger note: `server.js` listens on `"passenger"` when CloudLinux Passenger is present.

## 5. Smoke check

- https://community.elbeegems.com — home
- https://community.elbeegems.com/about
- https://community.elbeegems.com/directory
- https://community.elbeegems.com/login — form shows; submit stays browse-only (no real login)

## Notes

- Login / register are intentionally disabled for this mockup.
- SQLite file `prisma/dev.db` is the mock database (no MySQL).
- If the app 502s, check the Node app log and that `npm run build` finished on the server.
- SSL: use AutoSSL for `community.elbeegems.com` in cPanel.
