# Deploying SatchTech to Namecheap (satch.zonsegroup.com)

This package is already built (`.next` is included), so you don't need to run `npm run build` on the server.
It does not include `node_modules`. cPanel installs those for you.

## 1. Database

1. Go to cPanel → **MySQL Databases**. Create a database and a user, then give the user **ALL PRIVILEGES** on the database.
2. Write down the full names. cPanel adds your account prefix, for example `zonsxxxx_satch`.

## 2. Upload

1. Go to cPanel → **File Manager**. Create a folder **outside** `public_html`, for example `/home/<cpanel-user>/satch`.
2. Upload `satch-production.zip` to that folder and **Extract** it.
   - `.next` is a hidden folder. To check that it extracted, turn on *Settings → Show Hidden Files*.

## 3. Create the Node.js app

cPanel → **Setup Node.js App** → **Create Application**:

| Field | Value |
|---|---|
| Node.js version | **22.x** |
| Application mode | **Production** |
| Application root | `satch` (the folder from step 2) |
| Application URL | `satch.zonsegroup.com` |
| Application startup file | `server.js` |

Add these **environment variables** before you start the app:

```text
NODE_ENV=production
SITE_URL=https://satch.zonsegroup.com
DB_HOST=localhost
DB_PORT=3306
DB_USER=<cpanel-prefixed db user>
DB_PASS=<db password>
DB_NAME=<cpanel-prefixed db name>
CLOUDINARY_CLOUD_NAME=
CLOUDINARY_API_KEY=
CLOUDINARY_API_SECRET=
SMTP_HOST=
SMTP_PORT=465
SMTP_USER=
SMTP_PASS=
SMTP_FROM=
ENQUIRY_NOTIFY_TO=
ANTHROPIC_API_KEY=
ANTHROPIC_MODEL=
```

Click **Create**, then **Run NPM Install**. If a `node_modules` folder already exists in the app root, delete it first. cPanel manages `node_modules` as a symlink.

## 4. Create tables and the admin account

The app's environment variables aren't passed to the cPanel terminal, so the scripts read `.env.local`.

1. In the app folder, create `.env.local` with the same `DB_*` values as above.
2. Copy the "Enter to the virtual environment" command shown at the top of the Node.js app page. Run it in cPanel → **Terminal**, then:

```bash
cd ~/satch
npm run db:migrate
npm run admin:create
```

3. Optional: `npm run email:test` checks the SMTP settings.
4. Optional: after setup, delete `.env.local` or restrict its permissions with `chmod 600 .env.local`.

## 5. SSL and restart

1. Go to cPanel → **SSL/TLS Status** (AutoSSL). Make sure `satch.zonsegroup.com` has a certificate, because admin cookies and HSTS require HTTPS.
2. In **Setup Node.js App**, click **Restart**.
3. Open https://satch.zonsegroup.com and https://satch.zonsegroup.com/admin/login.

## Updating later

1. On your PC, run `npm run build` with `SITE_URL=https://satch.zonsegroup.com` set.
2. Rebuild the zip, upload it, and extract it over the old files. Replace the `.next` folder.
3. Click **Run NPM Install** if the dependencies changed, then click **Restart**.

## Troubleshooting

- **503 or "Incomplete response"**: check `stderr.log` in the app root. The usual causes are a missing `DB_*` variable or skipping NPM Install.
- **Out of memory or processes killed**: shared plans limit RAM. The app is already built, so only the runtime needs memory. If this keeps happening, ask Namecheap support to check your LVE limits.
