# SiloMart — live cPanel deploy (no SSH)

Use this file after you unzip the package. Do **not** run `next build` on the server.

---

## What you should have

From your computer, after `npm run deploy:local-package`:

| File | Use |
|------|-----|
| `dist-cpanel/project-prebuilt.zip` | Upload in cPanel File Manager |
| `dist-cpanel/project-prebuilt.tar.gz` | **Preferred** if ZIP extract breaks `.next` |
| `deploy/silomart-import.sql` | phpMyAdmin import (also inside the zip) |

---

## Step 1 — Create the database

1. cPanel → **MySQL® Databases** (or MariaDB)
2. Create a database (example: `silomart`)
3. Create a database user with a strong password
4. Add that user to the database with **ALL PRIVILEGES**
5. Write down: host (usually `localhost`), port (`3306`), database name, user, password

## Step 2 — Import SQL

1. cPanel → **phpMyAdmin**
2. Click the **new empty database** in the left sidebar
3. **Import** → Choose file → select `silomart-import.sql` (inside the extracted `deploy/` folder, or from this package)
4. Click **Go** and wait until it finishes

This creates tables, SiloMart settings, policy pages, and starter users.  
**Do not import into a database that already has live orders** unless you intend to wipe it.

## Step 3 — Upload the website

1. cPanel → **File Manager** → turn on **Show Hidden Files**
2. Open the folder used as the **Node.js application root**
3. Upload `project-prebuilt.zip` (or `.tar.gz`)
4. Extract it **into that same folder**
5. Confirm these sit next to each other (not one folder deeper):
   - `server.js`
   - `package.json`
   - `.next` (hidden — only visible with Show Hidden Files)
   - `public`
   - `prisma`
   - `scripts`
   - `deploy`

If extract created a `silomart/` (or `fliemart/`) subfolder, **move all files up** into the application root.

Prefer `.tar.gz` if you later see `EACCES` on `.next/static`.

## Step 4 — Setup Node.js App

1. cPanel → **Setup Node.js App**
2. Create / edit:
   - **Node.js version:** 20 or newer
   - **Application mode:** Production
   - **Application root:** the folder from Step 3
   - **Application URL:** your domain
   - **Application startup file:** `server.js`
3. Save

## Step 5 — Environment variables

In the Node.js App screen, 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` (or what cPanel shows) |
| `DB_PORT` | `3306` |
| `DB_USER` | your MySQL user |
| `DB_PASSWORD` | your MySQL password |
| `DB_NAME` | your database name |

Leave these **unset** on live:

- `ALLOW_DEMO_CHECKOUT`
- `ENABLE_STATUS_ENDPOINT`

For live card payments (optional now, required for paid checkout):

| Name | Value |
|------|--------|
| `STRIPE_SECRET_KEY` | Stripe secret key |
| `NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY` | Stripe publishable key |
| `STRIPE_WEBHOOK_SECRET` | from Stripe → Webhooks |

Save, then **Stop → Start** after any env change.

## Step 6 — Install and fix paths

In **Setup Node.js App**, one at a time:

1. **Run NPM Install** (wait until it finishes)
2. **Run JS Script:** `scripts/cpanel-prisma-generate.js`
3. **Run JS Script:** `scripts/cpanel-fix-paths.js`
4. **Run JS Script:** `scripts/cpanel-fix-perms.js`
5. Click **Stop**, then **Start** (not Restart alone)

## Step 7 — Check the live site

Open:

1. `https://your-domain.com/` — SiloMart storefront
2. `https://your-domain.com/api/health` — must be JSON, not a blank HTML error
3. `https://your-domain.com/login` — email + password only (no seed passwords on the page)

Starter accounts are **only** in the SQL comments. Change them immediately:

- Admin: `admin@silomart.com` / `admin123` → `/admin`
- Customer: `alex@example.com` / `password123`

After first login: Admin → change password (or phpMyAdmin → `User` table).

## Step 8 — Stripe webhook (when payments go live)

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

---

## Common problems

| What you see | What to do |
|--------------|------------|
| Internal Server Error / text/plain | Run prisma-generate + fix-paths, then Stop → Start. Confirm `.next` is next to `server.js`. |
| App inaccessible / 503 | Stop → Start; confirm startup file is `server.js` |
| Cannot find module `next` | Application root is wrong, or NPM Install did not finish |
| `EACCES` on `.next/static` | Re-upload `.tar.gz` (not Windows ZIP); run fix-perms |
| Health JSON says database down | Check `DB_*`; re-import `deploy/silomart-import.sql` into the **same** database |
| Checkout says Stripe is not configured | Add Stripe keys in env **or** Admin → Settings → Stripe, then Stop → Start |
| Login fails after import | You imported into a different database than `DB_NAME` |

---

## Security

- Change the seed admin password on day one
- Keep `AUTH_SECRET` and Stripe keys only in cPanel Environment Variables
- Do not enable demo checkout on production
- Only `public/uploads` needs to be writable
