# AkDevz AI Autonomous Quant Trading & Market Intelligence Platform
## Complete cPanel Production Deployment Guide
**Target Domain**: `https://trade.akdevz.sbs`  
**Database**: `rmjhsmjb_trade` | **User**: `rmjhsmjb_trade` | **Password**: `rmjhsmjb_trade`

---

## 1. Quick Deployment Summary

Everything has been configured and packaged for cPanel deployment:
- **Deployment Archive**: `cpanel_deploy_trade_akdevz_sbs.zip` (0.73 MB)
- **Database SQL Dump**: `rmjhsmjb_trade.sql` (1.3 MB, includes all 59 tables, 76 NSE/BSE assets, news sources, risk limits, and admin account)
- **Production Config**: `.env` (pre-configured with `https://trade.akdevz.sbs`, `rmjhsmjb_trade` database, and Groq/Gemini AI keys)
- **Apache Routing**: `.htaccess` in root and `public/.htaccess` (handles HTTPS, URL rewriting, GZIP compression, and blocks sensitive files)

---

## 2. Step-by-Step Deployment Instructions

### Step 1: Subdomain Setup on cPanel
1. Log in to your cPanel account.
2. Go to **Domains** -> **Create A New Domain** (or **Subdomains**).
3. Enter Domain: `trade.akdevz.sbs`.
4. Document Root: `/home/rmjhsmjb/trade.akdevz.sbs` (or `/home/rmjhsmjb/public_html/trade`).
5. Ensure **Force HTTPS Redirect** is enabled for the subdomain.

---

### Step 2: Upload and Extract Application Files
1. Open cPanel **File Manager**.
2. Navigate to your subdomain directory (e.g. `/home/rmjhsmjb/trade.akdevz.sbs/`).
3. Click **Upload** and select `cpanel_deploy_trade_akdevz_sbs.zip`.
4. Right-click the uploaded ZIP and click **Extract**.
5. Verify the extracted files:
   - `.env` (configured for `rmjhsmjb_trade`)
   - `.htaccess` (root router)
   - `public/` (contains `.htaccess`, `dashboard.php`, `login.php`, `market_behaviour.php`, `auto_trading.php`, etc.)
   - `app/` (PHP MVC controllers, models, repositories, views)
   - `python/` (quantitative analytics & trade execution engines)
   - `cron/` (automated scheduled tasks)
   - `rmjhsmjb_trade.sql` (database schema & data)
   - `requirements.txt` (Python dependencies)

> **Note**: If you do not see `.env` or `.htaccess`, click **Settings** (top right of File Manager) and check **"Show Hidden Files (dotfiles)"**.

---

### Step 3: Import Database via phpMyAdmin
1. In cPanel, navigate to **Databases** -> **phpMyAdmin**.
2. Select the database `rmjhsmjb_trade` from the left sidebar.
3. Click the **Import** tab at the top.
4. Click **Choose File** and select `rmjhsmjb_trade.sql` (from your computer or the extracted folder).
5. Click **Import** (or **Go**).
6. Success: All 59 tables, 76 verified assets, initial user accounts, and risk rules will be populated.

---

### Step 4: Install Dependencies on Shared cPanel (Choose ANY 1 of 4 Methods)

Since this is **shared cPanel hosting (not a VPS)**, you do **NOT** need root access or a black terminal. Choose whichever method is easiest for you:

---

#### 🟢 Method A: The 100% cPanel GUI Method (No Terminal Required — RECOMMENDED)
If your cPanel has **Setup Python App**, you never need to type any command:
1. In cPanel, scroll to the **Software** section and click **Setup Python App**.
2. Click **Create Application**:
   - **Python version**: `3.11` or `3.12`
   - **Application root**: `trade.akdevz.sbs` (or the folder where you extracted files)
   - **Application URL**: `trade.akdevz.sbs`
   - Click **Create** (top right).
3. Scroll down on the application page to the section titled **"Configuration files"**.
4. In the text field, type: `requirements.txt` and click the **"Add"** button.
5. You will see `requirements.txt` appear in the list with a button next to it: **"Run Pip Install"**.
6. Click **"Run Pip Install"**!
7. cPanel will install `pandas`, `numpy`, `PyMySQL`, `groq`, `yfinance`, and all dependencies into your private virtual environment in 45-60 seconds and show a green success notification!

---

#### 🟢 Method B: 1-Click Web Installer via Browser (ZERO cPanel Terminal Needed)
We have built an automated web installer directly into the platform:
1. Open your web browser and visit:  
   👉 `https://trade.akdevz.sbs/cpanel_installer.php`
2. It will automatically check your PHP version, MySQL database connection, and Python environment.
3. Click the big green button:  
   **"🚀 1-Click Install Python Dependencies"**
4. The web installer will run pip in the background and display the live installation progress directly on your web page!
5. Once all badges turn green (**✔ READY**), click **"🧪 Test Master Universe Sync"** to verify that the 76 NSE/BSE stock instruments sync into your database.
6. *(Important: Once setup is finished, delete or rename `public/cpanel_installer.php` using cPanel File Manager for security).*

---

#### 🖥️ Method C: How to Open cPanel Terminal (If Terminal is Enabled on Your cPanel)
If you prefer to use the cPanel web terminal:
1. Log in to your cPanel dashboard (`https://trade.akdevz.sbs:2083` or your host cPanel URL).
2. Look at the **search bar at the very top of cPanel** and type: `Terminal`.
   - *Alternatively, scroll down to the section named **"ADVANCED"** and look for the black icon labeled **"Terminal"**.*
3. Click the **"Terminal"** icon.
4. If a warning modal appears (*"Terminal access is provided for advanced users..."*), click **"I understand and want to proceed"**.
5. A black terminal window will open directly in your web browser.
6. If you created a Python app in Step 4A, copy the virtualenv command shown at the top of your Python app (or paste this):
   ```bash
   source /home/rmjhsmjb/virtualenv/trade.akdevz.sbs/3.11/bin/activate && cd /home/rmjhsmjb/trade.akdevz.sbs
   ```
   *(Note: To paste into cPanel Terminal, right-click inside the terminal and select **Paste**, or press **Ctrl + Shift + V** on Windows/Linux or **Cmd + V** on Mac).*
7. Press `Enter`.
8. Now paste and run:
   ```bash
   pip install --upgrade pip
   pip install -r requirements.txt
   ```
9. Verify with:
   ```bash
   python python/brokers/sync_instrument_master.py
   # Output: Successfully populated 76 authentic instruments into database universe.
   ```

> ⚠️ **What if the Terminal icon is missing in your cPanel?**  
> On many shared hosting plans (GoDaddy, Hostinger, Namecheap Shared, etc.), shared hosting providers disable the Terminal icon by default for security. **This is completely normal!** You do NOT need Terminal. Simply use **Method A** (the cPanel GUI button) or **Method B** (our Web Installer at `https://trade.akdevz.sbs/cpanel_installer.php`).

---

#### ⏱️ Method D: The 1-Time cPanel Cron Job Trick (Works on ANY cPanel Host)
If Terminal is disabled and your cPanel host does not have "Setup Python App":
1. In cPanel, click **Cron Jobs** (under the "Advanced" section).
2. Under "Add New Cron Job", select **Once Per Minute** (`* * * * *`).
3. In the **Command** field, paste:
   ```bash
   python3 -m pip install -r /home/rmjhsmjb/trade.akdevz.sbs/requirements.txt --user > /home/rmjhsmjb/trade.akdevz.sbs/storage/logs/pip_install.log 2>&1
   ```
4. Click **"Add New Cron Job"**.
5. Wait 60 seconds for the cron to fire in the background.
6. Check `storage/logs/pip_install.log` in File Manager to confirm successful installation.
7. **Immediately delete this cron job** from cPanel so it doesn't run again.
8. All packages are now permanently installed in your cPanel user's local directory (`~/.local/lib/python3.x/site-packages`) and available to all Python scripts!

---

### Step 5: Configure cPanel Cron Jobs
In cPanel, search for **Cron Jobs** and configure the following automated workers:

| Job Name | Schedule | cPanel Cron Command |
| :--- | :--- | :--- |
| **News & Regulatory Sync** | Every 15 minutes (`*/15 * * * *`) | `/usr/local/bin/php /home/rmjhsmjb/trade.akdevz.sbs/cron/news_sync.php >/dev/null 2>&1` |
| **Intraday Market Scan** | Every 2 mins (Market Hours `*/2 3-10 * * 1-5`) | `/usr/local/bin/php /home/rmjhsmjb/trade.akdevz.sbs/cron/intraday.php >/dev/null 2>&1` |
| **Pre-Market Analysis** | Daily 08:45 IST (`15 3 * * 1-5`) | `/usr/local/bin/php /home/rmjhsmjb/trade.akdevz.sbs/cron/premarket.php >/dev/null 2>&1` |
| **Post-Market Audit** | Daily 16:00 IST (`30 10 * * 1-5`) | `/usr/local/bin/php /home/rmjhsmjb/trade.akdevz.sbs/cron/postmarket.php >/dev/null 2>&1` |
| **System Cache Cleanup** | Daily at Midnight (`0 0 * * *`) | `/usr/local/bin/php /home/rmjhsmjb/trade.akdevz.sbs/cron/cleanup.php >/dev/null 2>&1` |

*(Replace `/home/rmjhsmjb/trade.akdevz.sbs/` with your actual cPanel home directory path if different).*

---

### Step 6: File Permissions Checklist
Ensure the following directories are writable by the web server (File Manager -> Permissions):
- `app/storage/` -> `775`
- `storage/cache/` -> `775`
- `storage/logs/` -> `775`
- All `.php` files -> `644`
- All folders -> `755`

---

## 3. Platform Login & Access

- **Web Terminal**: `https://trade.akdevz.sbs/login.php`
- **Default Username**: `akdevz`
- **Default Password**: `AkDevz@Quant2025!`
- **Key Modules Available Immediately**:
  - `https://trade.akdevz.sbs/dashboard.php`: TradingView Lightweight Charts & Technical Telemetry
  - `https://trade.akdevz.sbs/market_behaviour.php`: Bull vs Bear Power Battle Bar & 4 Trader Quadrants
  - `https://trade.akdevz.sbs/auto_trading.php`: Autonomous Order Dispatch & Active Positions Square-Off
  - `https://trade.akdevz.sbs/portfolio.php`: Mathematical Reconciliation Ledger & Capital Base Config
  - `https://trade.akdevz.sbs/assets.php`: 76 Stock & Index Master Universe
  - `https://trade.akdevz.sbs/broker_management.php`: FYERS, Angel One, Upstox, Shoonya Connectors
  - `https://trade.akdevz.sbs/news.php`: Live Sentiment & Multi-Source News Feed

---

## 5. Troubleshooting: "Index of /" or "404 Not Found" on LiteSpeed

If your browser showed **"Index of /"** or **"404 Not Found on /login.php"**:

### Why it happened:
1. **Directory Listing ("Index of /")**: LiteSpeed looked for an `index.php` directly in `/home/rmjhsmjb/trade.akdevz.sbs/`. If the root index was missing or dotfiles (`.htaccess`) were hidden, LiteSpeed displayed the directory folder contents instead of launching the app.
2. **404 Not Found on `/login.php`**: When clicking the `public/` folder, the script redirected to `https://trade.akdevz.sbs/login.php`. Because `login.php` was stored inside `public/`, LiteSpeed could not find it at the domain root.

### How it is 100% Fixed:
The latest [cpanel_deploy_trade_akdevz_sbs.zip](file:///home/akdevz/akdevz_trading_bot/cpanel_deploy_trade_akdevz_sbs.zip) (2.7 MB) includes:
- **Root Front Controller**: [index.php](file:///home/akdevz/akdevz_trading_bot/index.php) in root folder (immediately eliminates `Index of /`).
- **Root Dispatcher Wrappers**: [login.php](file:///home/akdevz/akdevz_trading_bot/login.php), [dashboard.php](file:///home/akdevz/akdevz_trading_bot/dashboard.php), [cpanel_installer.php](file:///home/akdevz/akdevz_trading_bot/cpanel_installer.php), [auto_trading.php](file:///home/akdevz/akdevz_trading_bot/auto_trading.php), [market_behaviour.php](file:///home/akdevz/akdevz_trading_bot/market_behaviour.php) directly at root (eliminates 404 on `/login.php`).
- **Root Static Assets & APIs**: [assets/](file:///home/akdevz/akdevz_trading_bot/assets) and [api/](file:///home/akdevz/akdevz_trading_bot/api) mirrored at root so all CSS/JS load without rewrites.
- **LiteSpeed Compatibility**: [.htaccess](file:///home/akdevz/akdevz_trading_bot/.htaccess) configured with `DirectoryIndex index.php public/index.php` and `RewriteBase /`.

### To Apply on Your Server:
1. In cPanel **File Manager**, upload the new [cpanel_deploy_trade_akdevz_sbs.zip](file:///home/akdevz/akdevz_trading_bot/cpanel_deploy_trade_akdevz_sbs.zip) (2.7 MB).
2. Right-click and **Extract** (choose replace/overwrite).
3. Refresh `https://trade.akdevz.sbs` — it will immediately load the login screen!
