# BhoFit — live cPanel deploy (step by step)

Use **only** cPanel (no SSH). The zip already contains a production build. **Do not run `next build` on the server.**

---

## What you upload

From this computer, after packaging:

- `dist-cpanel/bhofit-cpanel.zip` (or `bhofit-cpanel-*.zip`)
- SQL is inside the zip at `deploy/fliemart-import.sql`

---

## Step 1 — Create the database

1. cPanel → **MySQL® Databases**
2. Create a database (example: `user_bhofit`)
3. Create a database user with a strong password
4. Add the user to the database with **ALL PRIVILEGES**
5. Write down: database name, username, password, host (`localhost`)

---

## Step 2 — Import SQL

1. cPanel → **phpMyAdmin**
2. Click your new database in the left sidebar
3. **Import** → Choose file → `deploy/fliemart-import.sql` (from the zip, after you extract — or upload that one file first)
4. Click **Go** and wait until it finishes

This file creates tables, BhoFit settings, policy pages, the clothing catalog, and the first admin user.

If phpMyAdmin times out, increase import size or import the same file again only on an **empty** database (it drops existing store tables).

---

## Step 3 — Setup Node.js App

1. cPanel → **Setup Node.js App** → Create
2. Set:
   - **Node.js version:** 20 or newer
   - **Application mode:** Production
   - **Application root:** the folder you will extract into (often `bhofit` or a subdomain document root)
   - **Application URL:** your domain or subdomain
   - **Application startup file:** `server.js`
3. Save (do not start yet if files are not uploaded)

---

## Step 4 — Upload and extract the zip

1. cPanel → **File Manager**
2. **Settings** → enable **Show Hidden Files** (needed for the `.next` folder)
3. Open the **same folder** as Application root
4. Upload `bhofit-cpanel.zip`
5. Right-click → **Extract**
6. If everything landed in a subfolder, move the contents **up** so these sit next to each other:

   - `server.js`
   - `package.json`
   - `.next` (hidden)
   - `public`
   - `prisma`
   - `scripts`
   - `deploy`

7. Delete the zip after extract if you want disk space back

---

## Step 5 — Environment variables

In **Setup Node.js App** → Environment Variables, add:

| Name | Value |
|------|--------|
| `NODE_ENV` | `production` |
| `AUTH_SECRET` | a long random string (16+ characters) |
| `NEXT_PUBLIC_SITE_URL` | `https://your-domain.com` (no trailing slash) |
| `DB_HOST` | `localhost` |
| `DB_PORT` | `3306` |
| `DB_USER` | your MySQL user |
| `DB_PASSWORD` | your MySQL password |
| `DB_NAME` | your database name |

For live card payments (Stripe):

| Name | Value |
|------|--------|
| `STRIPE_SECRET_KEY` | Stripe secret key (`sk_live_…` for live) |
| `NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY` | Stripe publishable key |
| `STRIPE_WEBHOOK_SECRET` | Webhook signing secret |

Leave **unset**: `ALLOW_DEMO_CHECKOUT`, `ENABLE_STATUS_ENDPOINT`.

Save.

---

## Step 6 — Install and fix paths

In **Setup Node.js App**:

1. **Run NPM Install** — wait until it finishes
2. **Run JS Script** (one at a time):
   1. `scripts/cpanel-prisma-generate.js`
   2. `scripts/cpanel-fix-paths.js`
   3. `scripts/cpanel-fix-perms.js`
   4. `scripts/cpanel-doctor.js` (optional check)

---

## Step 7 — Start

1. Click **Stop**
2. Click **Start**  
   (Stop → Start, not Restart only)

---

## Step 8 — Check the live site

1. `https://your-domain.com/` — storefront
2. `https://your-domain.com/api/health` — must be JSON, `"ok": true`
3. `https://your-domain.com/login` — sign-in form only (no demo accounts on the page)

### First admin login (change immediately)

- Email: `admin@bhofit.com`
- Password: `admin123`

Then: **Admin →** change password / create a new admin and remove the starter one if you prefer.

Stripe webhook URL (if using Stripe):

- `https://your-domain.com/api/webhooks/stripe`
- Events: `payment_intent.succeeded`, `payment_intent.payment_failed`

---

## Common problems

| What you see | What to do |
|--------------|------------|
| Site is a blank error / Internal Server Error | Confirm `.next` is next to `server.js` (Show Hidden Files). Run prisma-generate + fix-paths. Stop → Start. |
| `/api/health` is HTML, not JSON | App is not `server.js`, or Passenger is serving the wrong root. |
| Health JSON but database error | Check `DB_*` values. Re-import SQL on the **correct** database. Try `DB_HOST=127.0.0.1` then Stop → Start. |
| Cannot find module `next` | Application root is wrong, or NPM Install did not finish. |
| Products missing | Import `deploy/fliemart-import.sql` (it includes the catalog). |
| Card pay says unavailable | Add Stripe live keys, Stop → Start. |
| Permission errors on `.next` | Run `scripts/cpanel-fix-perms.js`. Prefer extracting with Show Hidden Files on. |

---

## After go-live

- Change the starter admin password
- Keep `AUTH_SECRET` and Stripe keys only in cPanel env vars
- Only `public/uploads` needs to be writable for media
- Never run `next build` on cPanel
