# cPanel Production Deployment Guide

## 1) Server Requirements
- PHP `8.2+`
- Composer `2.x`
- Node.js `20+` and npm
- MySQL/MariaDB
- SSH access (recommended)

## 2) Domain / Document Root
- Point your domain (or subdomain) document root to:
  - `your-project/public`
- If your host does not allow sub-folder document root:
  - Keep project outside `public_html`
  - Only expose `public/` content to web root

## 3) Production Environment File
- Copy `.env.production` to `.env`
- Set real values:
  - `APP_KEY` (generate with `php artisan key:generate --force`)
  - `DB_*`
  - `APP_URL`
  - `VITE_API_BASE_URL`
  - `CORS_ALLOWED_ORIGINS`
  - `SANCTUM_STATEFUL_DOMAINS`

## 4) One-Time Setup
```bash
php artisan key:generate --force
php artisan migrate --force
php artisan storage:link
```

## 5) Deploy Commands (Each Release)
```bash
composer install --no-dev --optimize-autoloader
npm ci
npm run build
php artisan migrate --force
php artisan optimize:clear
php artisan config:cache
php artisan route:cache
php artisan view:cache
php artisan event:cache
```

Or run:
```bash
bash scripts/deploy-cpanel.sh
```

## 6) Queue Worker (Important)
- Since `QUEUE_CONNECTION=database`, add a cPanel Cron job:
```bash
* * * * * cd /home/USERNAME/your-project && php artisan queue:work --stop-when-empty >> /dev/null 2>&1
```
- Prefer Supervisor if your host provides it.

## 7) Scheduler (If Needed)
```bash
* * * * * cd /home/USERNAME/your-project && php artisan schedule:run >> /dev/null 2>&1
```

## 8) Post-Deploy Checks
- `APP_DEBUG=false`
- `LOG_LEVEL=error`
- `php artisan about`
- Open app and verify:
  - login/session works across your domains
  - `/api/refresh-token` works
  - Vite assets load from `public/build/manifest.json`

## 9) Rollback
- Keep previous release copy and DB backup before each deployment.
- Roll back code + restore DB backup when needed.
