# GLETRA cPanel Deployment Guide

Deploy GLETRA on shared hosting with cPanel, SSH access, and Node.js support.

## Prerequisites

Your cPanel host must provide:

- PHP 8.2+ with extensions: `pdo_mysql`, `mbstring`, `openssl`, `gd`, `redis` (or use file cache)
- MySQL database
- SSH / Terminal access
- Node.js Selector (for building assets)
- SSL certificate (AutoSSL or Let's Encrypt)
- Ability to run long-lived processes OR cron-based queue

> **Note:** Laravel Reverb requires a persistent WebSocket process. If your host cannot run background daemons, use a VPS for Reverb only and point `REVERB_HOST` to that server.

## Step 1 — Upload files

1. Upload project to `~/gletra` (outside `public_html`) or directly into `public_html/gletra`
2. Point domain document root to `public/` subdirectory:

   In cPanel → Domains → Document Root: `/home/username/gletra/public`

## Step 2 — Create database

cPanel → MySQL Databases:

1. Create database `username_gletra`
2. Create user with full privileges
3. Note host (usually `localhost`)

## Step 3 — Configure `.env`

```bash
cd ~/gletra
cp .env.example .env
nano .env
```

```env
APP_ENV=production
APP_DEBUG=false
APP_URL=https://yourdomain.com

DB_DATABASE=username_gletra
DB_USERNAME=username_gletrauser
DB_PASSWORD=your_password
DB_HOST=localhost

CACHE_STORE=file
QUEUE_CONNECTION=database
SESSION_DRIVER=database
BROADCAST_CONNECTION=reverb

REVERB_HOST=yourdomain.com
REVERB_PORT=8080
REVERB_SCHEME=https
```

If Redis is unavailable, use `CACHE_STORE=file` and `QUEUE_CONNECTION=database`.

## Step 4 — Install via SSH

```bash
cd ~/gletra
composer install --no-dev --optimize-autoloader
php artisan key:generate
php artisan migrate --force
php artisan storage:link
php artisan gletra:generate-vapid-keys   # add keys to .env
```

## Step 5 — Build assets with Node.js Selector

cPanel → Setup Node.js App:

1. Create app pointing to project root
2. Node version 18+
3. Run:

```bash
npm install
npm run build
```

## Step 6 — PHP settings

cPanel → MultiPHP INI Editor:

```ini
upload_max_filesize = 512M
post_max_size = 512M
max_execution_time = 300
memory_limit = 256M
```

## Step 7 — Cron jobs

cPanel → Cron Jobs:

```cron
* * * * * /usr/local/bin/php /home/username/gletra/artisan schedule:run >> /dev/null 2>&1
* * * * * /usr/local/bin/php /home/username/gletra/artisan queue:work --stop-when-empty >> /dev/null 2>&1
```

## Step 8 — Laravel Reverb

### Option A — Same server (SSH with screen/tmux)

```bash
screen -S reverb
cd ~/gletra
php artisan reverb:start --host=0.0.0.0 --port=8080
# Ctrl+A, D to detach
```

### Option B — Reverse proxy via .htaccess (limited)

Some hosts proxy WebSocket through Apache. Add to `public/.htaccess` if supported:

```apache
RewriteCond %{HTTP:Upgrade} websocket [NC]
RewriteCond %{HTTP:Connection} upgrade [NC]
RewriteRule ^app/(.*)$ ws://127.0.0.1:8080/app/$1 [P,L]
```

Requires `mod_proxy_wstunnel`.

### Option C — External Reverb VPS

Run Reverb on a small VPS ($5/mo). Set:

```env
REVERB_HOST=reverb.yourdomain.com
VITE_REVERB_HOST=reverb.yourdomain.com
```

## Step 9 — Permissions

```bash
chmod -R 775 storage bootstrap/cache
```

## Step 10 — Admin user

Register at your site, then in phpMyAdmin:

```sql
UPDATE users SET is_admin = 1 WHERE email = 'you@example.com';
```

## Common cPanel issues

| Problem | Solution |
|---------|----------|
| 500 error | Check `storage/logs/laravel.log`; fix permissions |
| Assets 404 | Run `npm run build`; verify `public/build/` exists |
| WebSocket fails | Reverb not running; check firewall on port 8080 |
| Large upload fails | Increase PHP limits in MultiPHP INI |
| Queue not processing | Verify cron for `queue:work` |

## SSL requirement

WebRTC calls and browser push require HTTPS. Enable AutoSSL in cPanel before testing calls.
