# Deploy Edil Bingo Admin on cPanel

Domain: **https://edilapk.makalla.org**

This guide is for cPanel hosting with **Setup Node.js App** (also called *Application Manager* on some hosts).

---

## Before you start

You need:

- cPanel login for **makalla.org**
- **Setup Node.js App** available in cPanel (ask your host if you don’t see it)
- Node.js **18** or **20** on the server
- Subdomain **edilapk.makalla.org** (we create this below)

---

## Step 1 — Create the subdomain

1. Log in to **cPanel**
2. Open **Domains** → **Create A New Domain** (or **Subdomains** on older cPanel)
3. Create:
   - **Domain:** `edilapk.makalla.org`
   - **Document root:** e.g. `edilapk` (cPanel may suggest `public_html/edilapk` — that is fine)
4. Save

If DNS is not automatic, add an **A record** for `edilapk` pointing to your server IP (your host usually does this when you create the subdomain in cPanel).

---

## Step 2 — Upload the admin files

On your PC, zip the **`admin`** folder contents (not the parent `Mobile` folder).

**Include:**
- `server/`
- `public/`
- `package.json`
- `package-lock.json`
- `data/` (can be empty — app creates files)
- `uploads/apk/` (empty folder is OK)

**Do NOT upload:**
- `node_modules/` (cPanel will install this)
- `cookies.txt`
- `.env` files with secrets (use cPanel env vars instead)

**Upload via cPanel:**

1. **File Manager**
2. Go to the folder cPanel uses for the subdomain (e.g. `/home/youruser/edilapk` or `/home/youruser/public_html/edilapk`)
3. **Upload** the zip file
4. **Extract** so you see `server/`, `public/`, `package.json` directly inside that folder

Your folder should look like:

```
edilapk/
  package.json
  server/
    index.js
  public/
  data/
  uploads/
    apk/
```

---

## Step 3 — Create the Node.js application

1. cPanel → **Setup Node.js App** (or **Application Manager**)
2. Click **Create Application**
3. Fill in:

| Field | Value |
|--------|--------|
| **Node.js version** | 18.x or 20.x |
| **Application mode** | Production |
| **Application root** | `edilapk` (path to the folder from Step 2) |
| **Application URL** | `edilapk.makalla.org` |
| **Application startup file** | `server/index.js` |
| **Passenger log file** | (leave default) |

4. Click **Create**

---

## Step 4 — Environment variables

In the same **Setup Node.js App** page, open your app → **Environment variables** (or **Add Variable**).

Add these:

| Variable | Value |
|----------|--------|
| `NODE_ENV` | `production` |
| `PUBLIC_BASE_URL` | `https://edilapk.makalla.org` |
| `ADMIN_USERNAME` | your admin login (e.g. `admin`) |
| `ADMIN_PASSWORD` | **strong password** (not the default) |
| `ADMIN_SESSION_SECRET` | long random string (e.g. 32+ characters) |
| `DEFAULT_USER_BALANCE` | `100` |

**Do not set `PORT`** — cPanel sets it automatically.

Click **Save**.

---

## Step 5 — Install dependencies and start

On the Node.js app page:

1. Click **Run NPM Install** (or open **Terminal** in cPanel and run):

```bash
cd ~/edilapk
npm install --omit=dev
```

(Use your real path if different, e.g. `~/public_html/edilapk`.)

2. Click **Restart** (or **Start Application**)

3. Wait until status shows **Running**

---

## Step 6 — Folder permissions (important)

The app must write to `data/` and `uploads/apk/`.

In **File Manager**, for folders `data` and `uploads`:

- Right-click → **Change Permissions**
- Set to **755** (or **775** if 755 fails on your host)

If APK upload fails later, try **775** on `uploads` and `uploads/apk`.

---

## Step 7 — Enable SSL (HTTPS)

1. cPanel → **SSL/TLS Status** or **AutoSSL**
2. Run AutoSSL for **edilapk.makalla.org**
3. Confirm **https://edilapk.makalla.org** opens with a padlock

The mobile app requires **HTTPS**.

---

## Step 8 — Test the deployment

Open in a browser:

| URL | Expected |
|-----|----------|
| https://edilapk.makalla.org | Admin login page |
| https://edilapk.makalla.org/api/health | `{"ok":true,...}` |

Login with `ADMIN_USERNAME` and `ADMIN_PASSWORD` from Step 4.

---

## Step 9 — Upload the mobile APK

1. Login to admin
2. **App Release** tab
3. Set **Version** `1.0.1`, **Build** `2`
4. Upload `releases/edil-bingo-v1.0.1.apk` from your PC
5. Save

Check: **Install Links** tab should show an APK URL starting with `https://edilapk.makalla.org/downloads/...`

---

## Step 10 — Generate activation codes

1. **Devices & Activation** → **Generate Codes**
2. Give a code to each operator
3. They install the APK → enter code → app activates

Recharge balance using each device’s **Device ID** shown in the app.

---

## Troubleshooting

### “503 Service Unavailable” or blank page
- Node app not running → **Restart** in Setup Node.js App
- Wrong startup file → must be `server/index.js`
- Check **Passenger log** / **Error log** in cPanel

### “Cannot GET /api/health”
- App root wrong — `package.json` must be in the same folder as `server/`
- Restart the Node.js app after fixing files

### Admin login fails
- `ADMIN_PASSWORD` in env vars must match what you type
- After changing env vars, **Restart** the app
- Delete `data/admin.json` on server only if you need to reset admin (then restart — default account is recreated from env vars)

### APK upload fails
- Permissions on `uploads/apk/` → 755 or 775
- File size: APK ~60 MB — host must allow uploads (cPanel **PHP max upload** does not apply to Node; if it still fails, ask host to raise limit for Node/proxy)

### Mobile app “Could not reach admin server”
- Confirm `https://edilapk.makalla.org/api/health` works on the phone’s browser
- SSL must be valid (not self-signed)
- App uses `assets/config/server.json` → `"baseUrl": "https://edilapk.makalla.org"`

### Session / logout issues behind cPanel
- Ensure `NODE_ENV=production` is set
- Ensure `PUBLIC_BASE_URL=https://edilapk.makalla.org` (no trailing slash)

---

## After updates (redeploy)

1. Upload changed files (or new zip) via File Manager
2. **Run NPM Install** if `package.json` changed
3. **Restart** the Node.js application

---

## Backup (do this regularly)

Download from File Manager:

- `data/` — devices, activation codes, release info
- `uploads/apk/` — APK files

---

## Quick checklist

- [ ] Subdomain `edilapk.makalla.org` created
- [ ] Admin files uploaded and extracted
- [ ] Node.js app created, startup `server/index.js`
- [ ] Environment variables set (especially password + session secret)
- [ ] NPM install + Restart
- [ ] `data/` and `uploads/` permissions OK
- [ ] SSL enabled (HTTPS)
- [ ] `/api/health` returns OK
- [ ] APK uploaded in App Release
- [ ] Activation code generated and tested on a phone
