# SiloMart — cPanel / CloudLinux deployment

## Supported workflow

### Local machine

1. `npm install`
2. `npm run lint` (optional)
3. `npm run build` — **never on cPanel**
4. `npm run package:cpanel` → `dist-cpanel/silomart-cpanel-*.zip` (and `.tar.gz`)
5. Confirm archive contains `.next/`, `server.js`, `package.json`, `public/`, `prisma/`, `src/`, `deploy/`

### cPanel

1. File Manager → **Show Hidden Files**
2. Upload `.tar.gz` (prefer over Windows ZIP — avoids `EACCES` on `.next/static`)
3. Extract into the Node application root (avoid spaces in path when possible)
4. Verify `.next` and `server.js` exist
5. **Setup Node.js App**
   - Node 20+
   - Startup file: `server.js`
   - Mode: Production
6. Configure Environment Variables (`deploy/ENV-CHECKLIST.md`)
7. phpMyAdmin: import `deploy/silomart-import.sql`
8. **Run NPM Install**
9. Run JS Script (recommended once):
   - `scripts/cpanel-fix-paths.js`
   - `scripts/cpanel-fix-perms.js`
   - `scripts/cpanel-doctor.js`
10. **STOP** then **START** the app (prefer over Restart alone)
11. Live checks:
    - `BASE=https://your-domain.com npm run check:live` (from your PC)
    - Or open `/api/health`

## Helper scripts (Run JS Script)

| Script | Purpose |
|--------|---------|
| `scripts/cpanel-doctor.js` | Verify root, `.next`, deps, env presence (no secret values) |
| `scripts/cpanel-deps.js` | Dependency diagnostics |
| `scripts/cpanel-clean.js` | Remove `.next/cache` / stale artifacts |
| `scripts/cpanel-fix-perms.js` | dirs `755` / files `644` |
| `scripts/cpanel-fix-paths.js` | Fix Windows paths in `required-server-files.json` |

## Permissions model

- Directories: `755`
- Files: `644`
- Writable runtime dir: `public/uploads` only
- Do **not** write into `.next` at runtime
- Do **not** make the whole app world-writable

## Avoiding 503 / "app inaccessible"

| Symptom | Fix |
|---------|-----|
| Cannot find module `next` | Wrong app root or NPM Install not run |
| `EACCES` on `.next/static` | Re-extract `.tar.gz`; run fix-perms; avoid Windows ZIP |
| No production build | Upload prebuilt `.next` |
| NPM app inaccessible | `server.js` must keep listening; STOP→START; check logs |
| WASM OOM on build | Never build on server — deploy prebuilt |
| `/api/health` db disconnected | Check `DB_*` / import schema in phpMyAdmin |

## Diagnostics

- `/api/health` — safe JSON readiness
- `/__status` — temporary; enable with `ENABLE_STATUS_ENDPOINT=true`, then disable

## Admin security

- Privileges come from server session + DB role (`requireAdmin`), never from browser flags
- Change default seed credentials (`admin@silomart.com`) immediately on any shared/prod DB
