# EasyStream - Docker Quick Start

**Get your video platform running in under 5 minutes!**

---

## Prerequisites

- Docker installed
- Docker Compose installed
- 2GB free disk space

---

## Installation

### Step 1: Start the Platform

```bash
docker-compose up -d --build
```

This starts all required services:
- **db** - MariaDB database
- **php** - PHP-FPM 8.2 application server
- **caddy** - Web server with automatic HTTPS
- **srs** - Live streaming server (RTMP/HLS)
- **cron** - Background jobs
- **abr** - Adaptive bitrate transcoding

---

### Step 2: Initialize Database (single SQL file)

Run this **once** after first launch:

```bash
docker exec -i easystream-db mysql -u easystream -peasystream easystream < __install/easystream.sql
```

This loads the full schema and default settings in one pass.

---

### Step 3: Access Your Platform

- **Main Site:** http://localhost:8083
- **Admin Panel:** http://localhost:8083/admin_login.php
- **Settings:** http://localhost:8083/admin_settings.php

**Default Admin Login:**
- Username: `admin`
- Password: `admin123`

---

## First Steps After Installation

### 1. Configure Basic Settings

Go to: http://localhost:8083/admin_settings.php

**General Tab:**
- Set your site name
- Update admin email
- Configure main URL (if not localhost)

**Modules Tab:**
- Enable/disable features you want (videos, live, blogs, etc.)

**Branding Tab:**
- Set your brand colors
- Upload logo and favicon

---

### 2. Set Up Email (Optional)

**Email Tab:**
- Configure SMTP settings for transactional emails
- Test with providers like SendGrid, Mailgun, or Gmail

Example for Gmail:
- Host: `smtp.gmail.com`
- Port: `587`
- Encryption: `TLS`
- Username: Your Gmail address
- Password: App-specific password ([Create here](https://myaccount.google.com/apppasswords))

---

### 3. Configure Payments (Optional)

**Payments Tab:**

**For PayPal:**
- Add PayPal email
- Add Client ID and Secret
- Toggle test mode (disable for production)

**For Stripe:**
- Enable Stripe
- Add Publishable Key
- Add Secret Key
- Add Webhook Secret

---

### 4. Set Up Creator Payouts (Optional)

**Payouts Tab:**
- Enable creator payout system
- Set revenue share percentage (e.g., 70% to creators)
- Set minimum payout amount
- Choose payout schedule (monthly recommended)

---

## Environment Variables

Create `.env` file to override defaults:

```env
# Database
DB_HOST=db
DB_NAME=easystream
DB_USER=easystream
DB_PASS=easystream

# Application
MAIN_URL=http://localhost:8083
DEBUG_MODE=0

# Email (optional - can also configure via admin panel)
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USER=your-email@gmail.com
SMTP_PASS=your-app-password
```

---

## Common Commands

### View Logs
```bash
# All services
docker-compose logs -f

# Specific service
docker-compose logs -f php
docker-compose logs -f caddy
docker-compose logs -f db
```

### Restart Services
```bash
# All services
docker-compose restart

# Specific service
docker-compose restart php
```

### Stop Platform
```bash
docker-compose down
```

### Stop and Remove Data
```bash
docker-compose down -v
```

### Database Access
```bash
# MySQL shell
docker exec -it easystream-db mysql -u easystream -peasystream easystream

# Run SQL file
docker exec -i easystream-db mysql -u easystream -peasystream easystream < file.sql
```

---

## File Structure

```
easystream/
├── docker-compose.yml          # Container orchestration
├── Caddyfile                   # Web server config
├── __install/                  # Installation scripts
│   └── install_settings_system.sql  # Settings installation
├── admin/                      # Admin panel
│   └── admin_settings.php      # Settings UI
├── f_core/                     # Core framework
│   ├── f_classes/              # PHP classes
│   └── config.*.php            # Configuration files
├── f_data/                     # Runtime data (auto-created)
│   ├── logs/                   # Application logs
│   └── cache/                  # Cache files
└── SETTINGS_GUIDE.md           # Complete settings documentation
```

---

## Live Streaming

### Start Streaming

**Push RTMP stream to:**
```
rtmp://localhost:1935/live/YOUR_STREAM_KEY
```

**View HLS stream at:**
```
http://localhost:8083/hls/live/YOUR_STREAM_KEY/index.m3u8
```

### OBS Studio Setup

1. Open OBS Studio
2. Settings → Stream
3. Service: `Custom`
4. Server: `rtmp://localhost:1935/live`
5. Stream Key: `YOUR_STREAM_KEY`
6. Click "Start Streaming"

---

## Troubleshooting

### Database Connection Errors

```bash
# Check if database is running
docker-compose ps

# Restart database
docker-compose restart db

# Check database logs
docker-compose logs db
```

---

### Settings Not Loading

```bash
# Re-run settings installation
docker exec -i easystream-db mysql -u easystream -peasystream easystream < __install/easystream.sql

# Check if settings exist
docker exec -it easystream-db mysql -u easystream -peasystream -e "SELECT COUNT(*) FROM easystream.db_settings;"
```

---

### Port Already in Use

If port 8083 is already in use, edit `docker-compose.yml`:

```yaml
services:
  caddy:
    ports:
      - "8084:80"  # Change 8083 to 8084
      - "443:443"
```

Then restart:
```bash
docker-compose down
docker-compose up -d
```

---

### Permission Errors

```bash
# Fix data directory permissions
sudo chown -R $(whoami):$(whoami) f_data/

# Or make writable by all (less secure)
chmod -R 777 f_data/
```

---

### Email Not Sending

1. Check SMTP settings in admin panel
2. Test credentials with a mail client
3. Check firewall allows port 587/465
4. Review application logs:
   ```bash
   docker-compose logs php | grep -i mail
   ```

---

## Production Deployment

### 1. Update Environment

Create `.env.production`:

```env
DB_HOST=db
DB_NAME=easystream
DB_USER=easystream
DB_PASS=STRONG_PASSWORD_HERE

MAIN_URL=https://yourdomain.com
DEBUG_MODE=0
```

### 2. Configure Domain

Edit `Caddyfile`:

```
yourdomain.com {
    root * /var/www/html
    php_fastcgi php:9000
    file_server
    encode gzip
}
```

### 3. SSL/HTTPS

Caddy automatically handles HTTPS with Let's Encrypt. Just point your domain to your server's IP.

### 4. Security Checklist

- [ ] Change default admin password
- [ ] Disable debug mode
- [ ] Use strong database password
- [ ] Enable HTTPS
- [ ] Configure firewall
- [ ] Set up regular backups
- [ ] Review security settings in admin panel

### 5. Backups

```bash
# Backup database
docker exec easystream-db mysqldump -u easystream -peasystream easystream > backup_$(date +%Y%m%d).sql

# Backup settings to JSON
# (from admin panel: Settings → Export)

# Backup uploaded files
tar -czf uploads_backup.tar.gz f_data/
```

---

## Performance Tips

### 1. Enable Redis Caching

Settings automatically use Redis when available for 10-100x faster performance.

Add to `docker-compose.yml`:

```yaml
services:
  redis:
    image: redis:7-alpine
    volumes:
      - redis_data:/data

volumes:
  redis_data:
```

### 2. Enable OPcache

Already enabled in the Docker PHP image for optimal performance.

### 3. Database Optimization

```bash
# Check database size
docker exec -it easystream-db mysql -u easystream -peasystream -e "
  SELECT table_schema AS 'Database',
         ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS 'Size (MB)'
  FROM information_schema.tables
  WHERE table_schema = 'easystream'
  GROUP BY table_schema;"

# Optimize tables
docker exec -it easystream-db mysqlcheck -u easystream -peasystream --optimize easystream
```

---

## Next Steps

1. **Read Full Documentation:** [SETTINGS_GUIDE.md](SETTINGS_GUIDE.md)
2. **Configure Your Platform:** Use the admin settings panel
3. **Upload Content:** Start creating videos, streams, or blogs
4. **Invite Users:** Share your platform URL
5. **Monitor Performance:** Check logs and system status regularly

---

## Support

- **Documentation:** See [SETTINGS_GUIDE.md](SETTINGS_GUIDE.md) for complete settings reference
- **Logs:** Check `f_data/logs/` for error logs
- **Admin Panel:** Use log viewer at `/admin/log_viewer.php`

---

## License

EasyStream Proprietary License Agreement
Copyright (c) 2025 Sami Ahmed. All rights reserved.



