# Deploy to Namecheap cPanel — payments.domain.com

This app is **Node.js + MySQL**. Namecheap shared hosting runs Node apps through
cPanel's **"Setup Node.js App"** (Passenger). Follow these steps.

---

## 1. Create the subdomain
cPanel → **Domains** (or **Subdomains**) → create **`payments`** on `domain.com`.
Note the document root it creates, e.g. `/home/USER/payments.domain.com`.

## 2. Create the MySQL database
cPanel → **MySQL® Databases**:
1. **Create New Database** → e.g. `tmify` → full name becomes `USER_tmify`.
2. **Add New User** → e.g. `tmify` → set a strong password → full name `USER_tmify`.
3. **Add User To Database** → select the user + database → grant **ALL PRIVILEGES**.

Write down: **DB name**, **DB user**, **DB password** (all three usually start with `USER_`).

> You don't need to create any tables — the app creates them automatically on first run.

## 3. Upload the app
1. cPanel → **File Manager** → go to the subdomain folder from step 1.
2. Upload **`tmify-portal.zip`** and **Extract** it there.
   (You should see `server.js`, `db.js`, `package.json`, `public/`, etc. directly in the folder.)
3. Delete the zip afterward.

## 4. Create the Node.js app
cPanel → **Setup Node.js App** → **Create Application**:
- **Node.js version:** 18 or 20 (newest available)
- **Application mode:** Production
- **Application root:** the subdomain folder (e.g. `payments.domain.com`)
- **Application URL:** `payments.domain.com`
- **Application startup file:** `server.js`
- Click **Create**.

## 5. Set environment variables
In the same Node.js App screen, add these variables (**Add Variable** for each):

| Name           | Value                                   |
| -------------- | --------------------------------------- |
| `DB_HOST`      | `localhost`                             |
| `DB_PORT`      | `3306`                                  |
| `DB_USER`      | `USER_tmify` (your DB user)             |
| `DB_PASSWORD`  | your DB password                        |
| `DB_NAME`      | `USER_tmify` (your DB name)             |
| `ADMIN_USER`   | `admin` (or your choice)                |
| `ADMIN_PASSWORD` | a strong password                     |

Do **not** set `PORT` — Passenger assigns it.

## 6. Install dependencies & start
On the Node.js App screen:
1. Click **Run NPM Install** (installs `express`, `mysql2`, `dotenv`).
2. Click **Restart**.

Visit **https://payments.domain.com/admin** and log in with the admin
username/password you set.

---

## Notes
- **HTTPS:** enable AutoSSL for the subdomain (cPanel → SSL/TLS Status) so the copy
  button and cookies work over https. The app also works over http.
- **Customer links** look like `https://payments.domain.com/invoice/<id>` — created and
  copyable from the admin panel after you create an invoice.
- **Change branding** (name, logo, color, tagline) in the admin panel → **Branding**.
- If the page shows a 503/"app failed to start", open **Setup Node.js App → log** — it's
  almost always wrong DB credentials in step 5.
