# cPanel Deployment ASAP (sales.globalerc.pt)

Use this when your domain is managed/hosted in cPanel and you need the app live quickly.

## 1) DNS first (critical)

In cPanel Zone Editor (or your registrar DNS):

- Host: `sales`
- Type: `A`
- Value: `<YOUR_CPANEL_SERVER_PUBLIC_IP>`
- TTL: `300`

Verify:

```bash
nslookup sales.globalerc.pt
```

It must resolve to your cPanel server IP.

---

## 2) Upload app code to cPanel

Upload project files to:

- `/home/<cpanel_user>/sales-dashboard`

Required files include:

- `app.py`
- `requirements.txt`
- `credentials.json`
- `templates/`
- `static/`
- `priority_actions_helper.py`
- `passenger_wsgi.py`

---

## 3) Create Python app in cPanel (Setup Python App)

In cPanel:

1. Open **Setup Python App**
2. Click **Create Application**
3. Configure:
   - Python version: `3.10+`
   - Application root: `sales-dashboard`
   - Application URL: `sales.globalerc.pt` (or subdomain mapping)
   - Application startup file: `passenger_wsgi.py`
   - Application Entry point: `application`

Then create app.

---

## 4) Install dependencies in cPanel virtualenv

In cPanel Terminal (or SSH), run:

```bash
cd ~/sales-dashboard
pip install -r requirements.txt
```

---

## 5) Set production environment variables in cPanel

In **Setup Python App** -> **Environment Variables** add:

- `APP_ENV=production`
- `BASE_URL=https://sales.globalerc.pt`
- `SECRET_KEY=<LONG_RANDOM_SECRET>`
- `SESSION_COOKIE_SECURE=true`
- `SESSION_COOKIE_SAMESITE=Lax`
- `PREFERRED_URL_SCHEME=https`

Do NOT add `OAUTHLIB_INSECURE_TRANSPORT` in production.

---

## 6) Google OAuth settings (required)

Google Cloud Console -> OAuth 2.0 Client -> Authorized redirect URIs:

- `http://localhost:5000/oauth2callback`
- `https://sales.globalerc.pt/oauth2callback`

Save changes.

---

## 7) Restart app in cPanel

In **Setup Python App**:

- Click **Restart** on the application.

Test:

- `https://sales.globalerc.pt`
- Login with Google
- Dashboard loads

---

## Fast troubleshooting

### 500 Internal Server Error

- Open cPanel Python app logs and check traceback.
- Confirm `credentials.json` exists in app root.
- Confirm packages installed in the app virtualenv.

### OAuth redirect mismatch

- Confirm exact URI in Google Console: `https://sales.globalerc.pt/oauth2callback`
- Confirm `BASE_URL=https://sales.globalerc.pt`

### DNS not propagated

- Wait 5-30 minutes (sometimes longer).
- Re-check with `nslookup sales.globalerc.pt`.

---

## If your cPanel does NOT have “Setup Python App”

You have two options:

1. Move app runtime to VPS/Linux with Nginx + gunicorn (recommended for full control).
2. Keep runtime elsewhere and use cPanel only for DNS (point `sales.globalerc.pt` to the real server IP).

Without Python App support, cPanel shared hosting cannot reliably run this Flask app process.
