# GLETRA Installation Guide

Complete setup for the GLETRA WhatsApp-style communication platform on a fresh server.

## Requirements

| Component | Version |
|-----------|---------|
| PHP | 8.2+ (8.3 recommended) |
| MySQL | 8.0+ |
| Redis | 6+ (cache + queues) |
| Node.js | 18+ |
| Composer | 2.x |
| SSL | Required for production WebRTC & push |

Optional: FFmpeg (video thumbnails/compression), Supervisor or systemd (process management).

## Step 1 — Clone and install dependencies

Use the **main project root** `.env` only. GletraChatBox (`Modules/GletraChatBox/`) does not have its own `.env`.

```bash
git clone <your-repo> gletra
cd gletra
composer install --no-dev --optimize-autoloader
cp .env.example .env
php artisan key:generate
```

## Step 2 — Configure environment

Edit the **root** `.env` (not `Modules/GletraChatBox/.env`):

```env
APP_NAME=GLETRA
APP_URL=https://your-domain.com

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_DATABASE=gletra
DB_USERNAME=gletra
DB_PASSWORD=your_password

CACHE_STORE=redis
QUEUE_CONNECTION=redis
SESSION_DRIVER=database
BROADCAST_CONNECTION=reverb

REVERB_APP_ID=123456
REVERB_APP_KEY=your_reverb_key
REVERB_APP_SECRET=your_reverb_secret
REVERB_HOST=127.0.0.1
REVERB_PORT=8080
REVERB_SCHEME=https

VITE_REVERB_APP_KEY="${REVERB_APP_KEY}"
VITE_REVERB_HOST="${REVERB_HOST}"
VITE_REVERB_PORT="${REVERB_PORT}"
VITE_REVERB_SCHEME="${REVERB_SCHEME}"
VITE_REVERB_ENABLED=true
```

Generate Web Push VAPID keys:

```bash
php artisan gletra:generate-vapid-keys
```

On Windows if OpenSSL fails, use:

```bash
npx web-push generate-vapid-keys
```

Copy the output into `.env` as `VAPID_PUBLIC_KEY`, `VAPID_PRIVATE_KEY`, and `VAPID_SUBJECT`.

## Step 3 — Database

```bash
php artisan migrate --force
php artisan storage:link
```

## Step 4 — Frontend assets

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

Chat assets build to `public/gc/build/` via `vite.gc.config.js` at project root.

## Step 5 — Create admin user

Register via `/register`, then:

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

## Step 6 — Start services

Development:

```bash
composer run dev          # Laravel + queue + Vite
php artisan reverb:start  # WebSocket server (separate terminal)
```

Production: use Supervisor/systemd (see [DEPLOYMENT.md](DEPLOYMENT.md)).

## Step 7 — Verify

1. Open `https://your-domain.com` and log in
2. Send a message between two browser tabs — real-time delivery via Reverb
3. Place an audio/video call — WebRTC signaling should connect
4. Check `/admin` dashboard (admin user only)
5. Allow browser notifications when prompted

## Troubleshooting

| Issue | Fix |
|-------|-----|
| Messages not real-time | Ensure Reverb is running and `BROADCAST_CONNECTION=reverb` |
| Calls fail to connect | Check microphone/camera permissions; HTTPS required |
| Push not working | Run `gletra:generate-vapid-keys`; HTTPS + service worker required |
| Stickers empty | Run migrations or import SQL dump |
| Upload fails | Check `storage/app/public` permissions and PHP `upload_max_filesize` |

## PHP upload limits

For large media (100 MB images/audio, 300 MB video), set in `php.ini`:

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

Document uploads have no app-level size cap (subject to PHP/server limits).
