# Deploy to cPanel (agentx.wisdomaxis.com)

This project is a **FastAPI (ASGI)** app. On cPanel it runs under **Phusion Passenger** using `passenger_wsgi.py`.

## What you upload

Use the generated **`agentx-cpanel-deploy.zip`**. Extract it so the **application root** (the folder that contains `passenger_wsgi.py`, `app/`, `static/`, `requirements.txt`) is the directory cPanel uses for the Python app.

## Steps in cPanel

1. **File Manager** (or SFTP): upload and extract `agentx-cpanel-deploy.zip` under your subdomain folder, e.g.  
   `~/agentx.wisdomaxis.com/`  
   so paths look like:  
   `~/agentx.wisdomaxis.com/passenger_wsgi.py`  
   `~/agentx.wisdomaxis.com/app/...`

2. **Setup Python App** (Software section):
   - **Python version**: 3.9 or newer (3.10+ recommended).
   - **Application root**: the folder above (where `passenger_wsgi.py` lives).
   - **Application URL**: your subdomain root `/` (typical for `agentx.wisdomaxis.com`).
   - **Application startup file**: `passenger_wsgi.py` (Passenger uses this automatically if configured; some UIs call it “WSGI file” — same file).
   - Create/start the app so cPanel builds the **virtualenv** and shows its path (copy it for `.htaccess`).

3. **Install dependencies** in that virtualenv (SSH or cPanel “Run Pip Install”):
   ```bash
   source /home/YOURUSER/virtualenv/agentx_wisdomaxis_com/3.11/bin/activate
   cd /home/YOURUSER/agentx.wisdomaxis.com
   pip install -r requirements.txt
   ```
   Replace paths with the ones cPanel shows.

4. **Apache / Passenger config**:
   - Copy `htaccess.CPANEL.example` to **`.htaccess`** in the same folder as `passenger_wsgi.py`.
   - Edit `PassengerAppRoot`, `PassengerPython`, and `PassengerBaseURI` to match your paths (see comments in the example).

5. **Permissions**: ensure the app can create the SQLite DB:
   ```bash
   chmod 755 data
   ```
   The first request creates `data/analytics.db` from `data/seed.sql`.

6. **Restart the application** (cPanel “Restart Python app” or touch `tmp/restart.txt` if your host documents that).

7. **Open** `https://agentx.wisdomaxis.com/` — you should see the chat UI. Check `https://agentx.wisdomaxis.com/api/health`.

## Optional: OpenAI

Create a `.env` file in the application root (same level as `passenger_wsgi.py`) with:

```
OPENAI_API_KEY=sk-...
```

Do **not** commit `.env` to public repos. The zip intentionally omits `.env`; use `.env.example` as a template.

## If charts or static files 404

Confirm `static/vendor/chart.umd.min.js` exists after extract. All static assets are served by FastAPI from `/static/...`.

## If Passenger rejects ASGI

Your host must run **Passenger 6+** with ASGI support. If the panel only supports WSGI, you would need a different layout (e.g. Gunicorn + reverse proxy); contact Wisdom Axis support with “ASGI / FastAPI / Passenger” in the ticket.

## Build the zip again (from your machine)

```bash
cd /path/to/zpoc
./scripts/build_cpanel_zip.sh
```

Output: `dist/agentx-cpanel-deploy.zip`.
