# Deploying Tradabi on cPanel

This takes about 20 minutes. You need a cPanel hosting plan that has **Setup Node.js App** (most plans on CloudLinux hosts such as Namecheap, Truehost, Whogohost, Hostinger cPanel plans, A2, etc. have it).

## Before you start

1. Log in to cPanel and search for **Setup Node.js App** (under *Software*). If it is not there, your plan cannot run Node.js. Ask your host to enable it, or upgrade/move to a plan that has it.
2. Download **tradabi-cpanel.zip** to your computer.
3. Decide on the web address. A subdomain such as `shop.yourdomain.com` is easiest. Do not install it in a sub-folder like `yourdomain.com/shop`; the app expects to be at the root of its address.

## Step 1: Create the subdomain (skip if you will use your main domain)

1. cPanel → **Domains** (or **Subdomains**) → **Create A New Domain**.
2. Enter `shop.yourdomain.com`. Untick "Share document root" if it is shown. Click **Submit**.

## Step 2: Upload the files

1. cPanel → **File Manager**. You start in your home folder (`/home/yourusername`).
2. Click **+ Folder** and create a folder named `tradabi`. Create it here in the home folder, **not** inside `public_html`.
3. Open the `tradabi` folder → **Upload** → choose `tradabi-cpanel.zip`. Wait for 100%.
4. Back in File Manager, right-click the zip → **Extract** → extract into `/home/yourusername/tradabi`.
5. You should now see `app.js`, `package.json`, `src`, `README.md` directly inside `tradabi`. If you see another `tradabi` folder inside instead, open it, select everything, **Move** it up one level.
6. Delete the zip file.

## Step 3: Create the Node.js application

1. cPanel → **Setup Node.js App** → **Create Application**.
2. Fill in:
   - **Node.js version**: choose the highest offered. 22.13 or newer is best. 18 or 20 also work (the app switches to a slower, built-in database mode automatically).
   - **Application mode**: Production
   - **Application root**: `tradabi`
   - **Application URL**: pick `shop.yourdomain.com` (leave the box after it empty)
   - **Application startup file**: `app.js`
3. Under **Environment variables**, click **Add Variable** for each:

   | Name | Value | What it does |
   |---|---|---|
   | `ADMIN_PHONE` | your phone, e.g. `08031234567` | Admin login phone |
   | `ADMIN_PASSWORD` | a strong password | Admin login password |
   | `BASE_URL` | `https://shop.yourdomain.com` | Used in affiliate links |
   | `DEMO` | `1` | Test mode: simulated payments and SMS codes on screen. Keep `1` until Paystack is connected |
   | `SEED_DEMO` | `1` to load sample products and demo users, `0` for an empty shop | Only used on the very first start |

   Optional:

   | Name | Value | What it does |
   |---|---|---|
   | `SETTINGS_KEY` | a long random phrase you keep somewhere safe | Locks the email, SMS and payment keys you save in **System setup**. If you leave it out, the app makes a key file, `tradabi/data/secret.key`, by itself. Either way, never share it |
   | `TRUST_PROXY` | leave unset (means `1`). Set `2` only if you put Cloudflare in front | Lets the app see visitors' real IP addresses for login limits and fraud checks |
   | `LEGAL_COMPANY` | your registered business name and number, e.g. `Tradabi Technologies Ltd (RC 1234567)` | Shown as the operator on the Terms and policy pages |
   | `LEGAL_ADDRESS` | your business address | Shown on the Terms and Privacy pages |
   | `SUPPORT_EMAIL` | e.g. `support@yourdomain.com` | Contact for complaints, disputes and policy questions |
   | `PRIVACY_EMAIL` | e.g. `privacy@yourdomain.com` (optional, defaults to `SUPPORT_EMAIL`) | Contact for data protection requests |

4. Click **Create**.

## Step 4: Install the app's packages

1. On the same page, scroll down. Click **Run NPM Install**. Wait until it says it finished (1–3 minutes).
2. Scroll up and click **Restart**.

If the button is greyed out, cPanel cannot see `package.json`: check Step 2.5.

## Step 5: Check it works

1. Open `http://shop.yourdomain.com/healthz`. You should see something like `{"ok":true,"db":"node:sqlite",...}`.
   - `"db":"sql.js"` is fine; it means your Node version is older than 22.13 and the fallback database is in use.
2. Open `http://shop.yourdomain.com`. You should see the shop.
3. Log in with your `ADMIN_PHONE` and `ADMIN_PASSWORD`. If you loaded demo data, the demo users (08000000001 to 08000000005, password `demo1234`) work too.
4. **Admin two-step login.** The first admin login asks you to set up an authenticator app. Install Google Authenticator (or Microsoft Authenticator or Authy) on your phone, scan the code on screen (or tap "Open in authenticator app" if you are on the phone), then type the 6-digit code it shows. You then see **8 recovery codes**: write them down and keep them away from your phone. From now on the admin login asks for the code from the app every time.

## Step 6: Turn on SSL (https)

1. cPanel → **SSL/TLS Status** → tick your subdomain → **Run AutoSSL**. Wait until it shows a green padlock (can take a few minutes, sometimes up to an hour after creating a new subdomain).
2. cPanel → **Domains** → switch **Force HTTPS Redirect** on for the subdomain.
3. Back in **Setup Node.js App** → edit Tradabi → add variable `FORCE_HTTPS` = `1` → **Save** → **Restart**.
4. Open `https://shop.yourdomain.com` and log in again.

## Step 7: Daily backups

The app already saves a compressed copy of the database every day into `tradabi/data/backups/` and keeps the newest 14. Because cPanel puts the app to sleep when nobody visits, also add a cron job so a backup happens even on quiet days:

1. cPanel → **Setup Node.js App**: at the top of Tradabi's page, copy the path in the command shown, e.g. `/home/yourusername/nodevenv/tradabi/22/bin/activate`. The Node program is the same path with `node` at the end instead of `activate`.
2. cPanel → **Cron Jobs** → **Add New Cron Job**. Common setting: **Once Per Day**. Command (change `yourusername` and `22` to match):
   ```
   /home/yourusername/nodevenv/tradabi/22/bin/node /home/yourusername/tradabi/scripts/backup.js
   ```
3. Click **Add New Cron Job**.

**Keep a copy off the server.** Once a week, log in as admin → **Backups** → **Download database**. It asks for your authenticator code. Save the `.db.gz` file on your computer or Google Drive. Backups contain every user's details, so never share them or put them inside `public_html`.

**Product photos, store logos and banners are not inside the database backup.** They live in `tradabi/data/uploads/`. Once a month (or after vendors add many products), in File Manager right-click `tradabi/data/uploads` → **Compress** → download the zip, or use cPanel → **Backup** → **Download a Home Directory Backup**.

**To restore a backup:** Setup Node.js App → **Stop App**. In File Manager, open `tradabi/data/`, delete `tradabi.db`, `tradabi.db-wal` and `tradabi.db-shm`, upload your backup, right-click it → **Extract** (it unpacks the `.gz`), rename the result to `tradabi.db`, then **Start App**.

## Removing the demo data

If you started with `SEED_DEMO` = `1`, the shop has 5 sample accounts (08000000001 to 08000000005) and their 6 products. To remove them:

1. Log in as admin → **Admin** → **Demo data**.
2. Check the list. It shows only the sample accounts; your admin account and every real seller, buyer and product stay. If a real account ever ordered a demo product, that test order is listed and removed too.
3. Type the code from your authenticator app and click **Confirm**.
4. Type `DELETE DEMO` in the box and click **Remove demo data**.

The app saves a backup first, so you can go back (see "To restore a backup" above). Then, in **Setup Node.js App** → edit Tradabi, set `SEED_DEMO` to `0` → **Save**. Demo data is only ever added on the very first start, so it does not come back on restart.

If that page warns that your admin still uses `08000000000` or `demo1234`, set `ADMIN_PHONE` and `ADMIN_PASSWORD` in Setup Node.js App, Save, then Restart.

## Hiding or removing a product from any store

Log in as admin → **Admin** → **Products**. Search by product or store name.

- **Hide** takes the product off sale at once. Type a reason if you like; the seller sees it on their dashboard. The seller cannot switch it back on. Click **Unhide** to put it back on sale.
- **Remove** is for good. It asks for your authenticator code first, then tick **Yes, remove it**. A product nobody has ordered is deleted with its photos. A product with past orders is kept out of sight instead, so those orders, payouts and disputes still work.

Every hide, unhide and remove is written to **Audit log** (filter by `admin.product`).

## Step 8: Connect email, SMS and payments (System setup)

Everything is typed into the admin pages; you do not edit any files. Log in as the admin (the `ADMIN_PHONE` account is the **owner** and a **super admin**) → **System setup**. It asks for your authenticator code before saving. Passwords and keys are stored locked (encrypted) and are only ever shown as `••••1234` afterwards.

**Email (needed for email confirmation and "forgot password")**
1. cPanel → **Email Accounts** → **Create**: for example `noreply@yourdomain.com` with a strong password.
2. Next to it click **Connect Devices**. Under **Secure SSL/TLS Settings** note the **Outgoing Server** (e.g. `mail.yourdomain.com`) and **SMTP Port** (`465`).
3. System setup → **Email**: host = that server, port `465`, security **SSL/TLS**, username = the full email address, password = its password, From email = the same address. **Save**.
4. **Send a test email** to yourself. Check spam the first time. If it fails, the red box shows what the mail server said.

**SMS with Africa's Talking**
1. Log in at account.africastalking.com, open your app. The app's **username** is shown there. Go to **Settings → API Key** and copy the key (shown once).
2. In Nigeria a custom **Sender ID** (like `Tradabi`) must be approved first; until then leave it empty.
3. Top up SMS credit. System setup → **SMS**: tick **Send SMS through Africa's Talking**, environment **Live**, username, API key → **Save** → **Send a test SMS** to your phone.
4. To practise first, use username `sandbox`, environment **Sandbox**, and the sandbox API key; messages then appear in Africa's Talking's simulator, not on phones.

**Payments with Paystack (or Flutterwave)**
1. Paystack dashboard → Settings → **API Keys & Webhooks**. Copy the **test** public and secret keys first.
2. System setup → **Payments**: gateway **Paystack**, mode **Test keys**, paste both test keys → **Save** → **Test connection**.
3. Back in Paystack (same page, test mode), paste the **Callback URL** and **Webhook URL** that System setup shows you.
4. Buy something on your shop with a Paystack test card to see the whole flow.
5. When ready: paste the live keys, set the live Callback and Webhook URLs in Paystack, choose **Live keys**, tick **I am ready to take real payments**, **Save**.
6. Flutterwave works the same way; you also make up a **webhook secret hash** and type the same phrase in Flutterwave → Settings → Webhooks.

With a real gateway, **payouts to sellers and affiliates are not sent automatically yet**. When money clears, it waits in Admin → **Payouts** under "Payouts to send". Send it from your Paystack/Flutterwave dashboard (Transfers) or your bank app, then type the transfer reference and click **Mark sent**. Refunds you approve appear there too, to send from the gateway dashboard.

**Then:** set `DEMO` to `0` and `SEED_DEMO` to `0`, keep `FORCE_HTTPS` at `1`, and restart. (System setup warns you if live keys are on while `DEMO` is still `1`.) The old `GATEWAY_SECRET` and `FLW_SECRET_HASH` variables are only used by the built-in simulator; once Paystack or Flutterwave is chosen in System setup they are ignored and you can delete them.

**Moving to a new server:** copy `tradabi/data/secret.key` along with the database (or set the same `SETTINGS_KEY`), otherwise type the keys into System setup again.

## Adding more admins

Admin → **Admin team** (super admins only).
1. Fill in their name, a phone number that has no Tradabi account yet, optional email, and a temporary password of at least 10 characters.
2. Tick what they may open: Orders & disputes, Products, Categories, Users, Payouts & refunds, Fraud & risk, Platform fee, Audit log, Backups & demo data. Tick **Super admin** only for someone you trust with everything (including adding admins and the payment keys).
3. Send them the phone number and temporary password privately. At first login they set up an authenticator app and pick their own password. They only see the parts you ticked.
4. **Manage** next to an admin lets you change what they can open, suspend them (logged out at once), set a new temporary password, or reset their two-step login if they lose their phone. Everything is written to the audit log.

The owner account (`ADMIN_PHONE`) can never be suspended or changed by other admins, and it is made super admin again on every restart, so you can always get back in.

## Sign-up, email confirmation and login

- New sign-ups give a phone number **and** an email, and must confirm the email with a 6-digit code (or the link in the same email) before using their account. The shop itself stays open to browse.
- People who signed up before this update are **not** blocked; their account page invites them to add or confirm an email.
- Everyone can log in with their phone number **or** their email. **Forgot your password?** on the login page sends a code by email (or SMS) once those are set up in System setup.
- Confirmation is only enforced once emails can really be sent (in test mode, `DEMO=1`, without email set up, the code is shown on screen instead). You can turn it off in System setup → **Sign-up & login**.
- Admin → **Users** can now **Suspend** a buyer, seller or affiliate (they are logged out at once) and **Restore** them.
- Check Admin → **Audit log** now and then: failed logins, payout account changes and refunds all appear there.

## Updating to a new version later

1. File Manager → `tradabi` → upload the new zip → Extract and allow it to overwrite files.
2. Your data, including product photos in `tradabi/data/uploads/`, lives in `tradabi/data/` and is not in the zip, so it is kept.
3. Setup Node.js App → **Run NPM Install** → **Restart**.

**Already installed under the old name (OjaLink)?** Keep your existing `ojalink` folder and Node.js app exactly as they are, and upload the new zip into that folder as above. Wherever this guide says `tradabi/`, read `ojalink/`. Your database stays `data/ojalink.db` and all your data, saved keys and backups keep working. Only the name people see changes to Tradabi. Update `BASE_URL` (and `SUPPORT_EMAIL`) when you move to the tradabi.com domain.

Updating to the version with the admin team, email confirmation and System setup needs **no new package** (Run NPM Install does no harm). The database adds its new columns on start. Your existing admin becomes the owner and super admin, and nobody who already has an account is locked out. Then follow Step 8 to connect email, SMS and payments.

Updating to the version with Terms of Service and policies needs no new package. The database adds two columns on start. Then, in **Setup Node.js App** → edit Tradabi, add `LEGAL_COMPANY`, `LEGAL_ADDRESS` and `SUPPORT_EMAIL` (see Step 3) → **Save** → **Restart**. The policies are at `/legal` (with short links `/terms`, `/privacy`, `/refunds`, `/cookies` that Paystack and Flutterwave ask for). New sign-ups must tick a box agreeing to them. **Have a Nigerian lawyer review the policies before launch**; while logged in as admin you see a reminder at the top of each policy page.

Updating to the version with category photos needs no new package. On the first start, each standard category that has no picture yet gets a free stock photo (in Admin → Categories you can replace or remove any of them, and removed ones do not come back). Photo credits are in `tradabi/defaults/categories/CREDITS.md`.

Updating to the version with the cart and product photos adds a new package (`busboy`, for photo uploads), so **Run NPM Install** is required this time. The database updates itself on start.

Updating to the version with admin product controls and demo removal needs no new package. The database adds two columns on start by itself. This zip no longer includes the `test` folder; if `tradabi/test` exists on your server from an earlier upload, you can delete it (the shop never uses it).

Updating to the version with vendor stores needs no new package (Run NPM Install does no harm). On start the database gives every existing vendor a store address made from their name (for example `/store/kano-naturals`). Store logos and banners are saved in `tradabi/data/uploads/` with the product photos, so the monthly uploads download covers them too.

Updating to the version with two-step login logs everyone out once (sessions are now stored differently). That is expected.

## Using the Terminal instead (optional)

If your cPanel has **Terminal**, the top of the Node.js app page shows a command like `source /home/you/nodevenv/tradabi/22/bin/activate && cd /home/you/tradabi`. Paste it, then you can run `npm install`, or `npm run seed` to add demo data later.

## Troubleshooting

| What you see | What to do |
|---|---|
| "It works! NodeJS …" placeholder page | Startup file is not `app.js`, or the app was not restarted. Fix it and click **Restart**. |
| "We're sorry, but something went wrong" or error 503 | Open `tradabi/stderr.log` in File Manager; the last lines say why. Most often NPM Install was not run or failed. Run it again, then Restart. |
| NPM Install fails or stops halfway | Shared plans limit memory. Try again once or twice. If it keeps failing, ask your host to run `npm install` in the app folder, or to raise the limit. |
| Log in does nothing, you are sent back to the login page | You set `FORCE_HTTPS=1` but opened the `http://` address. Use `https://`, or remove the variable until SSL works. |
| Affiliate links start with `http://` or the wrong address | Set `BASE_URL` to the exact `https://` address and Restart. |
| Pages look broken or 404 inside a folder like `/shop` | The Application URL has a path after the domain. Use a subdomain with an empty path instead. |
| "Database is locked" or "readonly" errors | In File Manager, set the `tradabi/data` folder permission to 755 and the `.db` file to 644. |
| Test email fails with "did not answer in time" | Try port 465 with SSL/TLS, or 587 with STARTTLS. Some hosts block outgoing mail ports to other servers; your own cPanel mail server (`mail.yourdomain.com`) always works. |
| Test SMS fails with "InsufficientBalance" or "InvalidSenderId" | Top up Africa's Talking credit, or leave Sender ID empty until yours is approved. |
| "Some saved keys cannot be read" in System setup | The `data/secret.key` file or `SETTINGS_KEY` changed (for example after moving servers). Type the keys again and save. |
| An admin forgot their password | Owner: change `ADMIN_PASSWORD` and restart. Other admins: a super admin sets a new temporary password in Admin team → Manage. Anyone can also use **Forgot your password?** once email or SMS is set up. |
| Admin password does not work | The admin login is reset from `ADMIN_PHONE` and `ADMIN_PASSWORD` every time the app starts. Check both variables, Save, then Restart. |
| Authenticator code is "not right" | Your phone's clock is off. Turn on automatic date and time in the phone's settings, then use the newest code. |
| Lost the phone with the admin authenticator, and the recovery codes | Add variable `ADMIN_RESET_2FA` with today's date as the value (e.g. `2026-11-26`), Save, Restart, log in and set up the authenticator again. Each value works only once, but remove the variable afterwards anyway. |
| "Too many attempts. Please wait…" | 5 wrong passwords or codes lock that account for 15 minutes. Wait and try again. |
| Everyone seems to share one IP in the audit log, or login limits hit many people at once | Set `TRUST_PROXY` to `2` if you use Cloudflare; otherwise leave it unset. |
| Payment webhooks return 401 | `GATEWAY_SECRET` (Paystack) or `FLW_SECRET_HASH` (Flutterwave) is missing or does not match the dashboard. |
| First page load after a quiet period is slow | Normal on shared hosting: the app sleeps when idle and wakes on the next visit. |

## Limits of shared cPanel hosting for this app

- **Good for a pilot**: a few hundred visitors a day and a few thousand orders is fine. When you outgrow it, move to a small VPS; the app is the same.
- **The app sleeps when idle.** Escrow releases and automatic payouts are checked on every visit, so they still happen, just at the next visit after they fall due.
- **Older Node versions** (below 22.13) use the fallback database, which rewrites the whole database file on each change. It is fine for small shops but slows as data grows. Pick Node 22+ if offered.
- **CPU and memory caps** (CloudLinux LVE limits). Heavy traffic spikes can return 503 errors.
- **Still in test mode.** Payments, SMS codes and BVN/NIN checks are simulated. Do not take real customers' money until Paystack (or Flutterwave) is connected and `DEMO` is set to `0`.
- **Disk space.** Product photos are stored as uploaded (up to 5 MB each, 6 per product), so watch your cPanel disk quota. Ask vendors to send phone photos at "medium" size; set `MAX_IMAGE_MB` (for example `2`) to lower the limit.
- **Rate limits and the audit log live in the same database file**, so they work across the several app processes cPanel may start. Very busy shops on the fallback database (Node below 22.13) will feel the extra writes; pick Node 22+.
