Video Streaming Setup
Video Streaming Server Setup
Page Location: N/A (Server Configuration)
Menu Path: N/A - Server-side setup
Access Level: System Administrator / Server Root Access
Last Updated: 2026-01-02
Overview
This guide covers the complete setup of the LiveKit WebRTC streaming server for ComusThumbz's live webcam streaming feature. LiveKit enables ultra-low-latency (sub-second) browser-to-browser video streaming, allowing creators to broadcast live directly from their webcams without requiring third-party streaming software.
The live streaming feature enables:
- Creators to broadcast live from
settings/golive.php - Viewers to watch streams at
watchstream.php - Interactive chat with real-time messaging and tips
- Private shows with per-minute token billing
- Access control (free, password, subscribers-only, PPV, tip goals)
State: Diagram showing: Browser → LiveKit Server → Viewers
Annotations: Show WebRTC flow from broadcaster to server to viewers
-->
System Requirements
LiveKit requires a dedicated server or VPS with specific ports and resources. It cannot run on shared hosting.
Server Requirements
Required Ports
These ports MUST be open in your firewall for LiveKit to function:
PHP Requirements (ComusThumbz Server)
Required PHP Extensions
External Tools
Installation Requirements
Config Settings (dat/config.inc.php)
Example config entries:
// LiveKit WebRTC Streaming Configuration
define('LIVEKITHOST', 'wss://streaming.yourdomain.com/livekit/');
define('LIVEKITAPIKEY', 'APIxxxxxxxxxxxxx');
define('LIVEKITAPISECRET', 'your-secret-key-here');
File Dependencies
Folders Required
Architecture Overview
How LiveKit Streaming Works
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ BROADCASTER │ │ LIVEKIT SERVER │ │ VIEWERS │
│ (Creator) │────▶│ (Media Server) │────▶│ (Subscribers) │
│ golive.php │ │ Docker Container│ │ watchstream.php│
└─────────────────┘ └──────────────────┘ └─────────────────┘
│ │ │
│ │ │
▼ ▼ ▼
WebRTC Publish SFU Routing WebRTC Subscribe
Video Track - Room Management - Video TrackAudio Track - Participant Auth - Audio Track
Data Channel - Media Relay - Chat Messages
Component Overview
Installation Methods
Method 1: Automated Setup Script (Recommended)
The automated script handles Docker installation, configuration, and API key generation automatically.
Step 1: Upload the Setup Script
Upload tools/setuplivekitserver.sh to your streaming server.
Step 2: Make Executable and Run
# Make the script executable
chmod +x setuplivekitserver.sh
Run with sudo
sudo ./setuplivekitserver.sh
Step 3: Follow Interactive Prompts
The script will:
- Detect your OS (Ubuntu/Debian)
- Install Docker if not present
- Configure firewall rules
- Auto-detect your public IP
- Generate API keys
- Create LiveKit configuration
- Start the LiveKit container
- Update your PHP configuration
Step 4: Note Your Credentials
At the end, the script outputs:
API Credentials:
API Key: APIxxxxxxxxxxxxxxxx
API Secret: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Save these credentials immediately! You'll need them for PHP configuration.
Method 2: Manual Installation (Debian 12)
For manual control or troubleshooting, follow these steps:
Step 1: Install Docker
# Update system
sudo apt update && sudo apt upgrade -y
Install prerequisites
sudo apt install -y apt-transport-https ca-certificates curl gnupg lsb-release
Add Docker GPG key
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
Add Docker repository
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian $(lsbrelease -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Install Docker
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
Start and enable Docker
sudo systemctl start docker
sudo systemctl enable docker
Verify installation
docker --version
Step 2: Configure Firewall
# UFW (Ubuntu/Debian)
sudo ufw allow 7880/tcp comment "LiveKit WebSocket"
sudo ufw allow 7881/tcp comment "LiveKit RTC TCP"
sudo ufw allow 50000:60000/udp comment "LiveKit WebRTC Media"
Or iptables directly
sudo iptables -A INPUT -p tcp --dport 7880 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 7881 -j ACCEPT
sudo iptables -A INPUT -p udp --dport 50000:60000 -j ACCEPT
Step 3: Generate API Keys
# Generate API Key (16 bytes, base64)
APIKEY=$(openssl rand -base64 16 | tr -d '/' | tr '+' '-')
echo "API Key: $APIKEY"
Generate API Secret (32 bytes, base64)
APISECRET=$(openssl rand -base64 32 | tr -d '/' | tr '+' '-')
echo "API Secret: $APISECRET"
Step 4: Create LiveKit Configuration
Create /opt/livekit/livekit-config.yaml:
# LiveKit Media Server Configuration
port: 7880
rtc:
portrangestart: 50000
portrangeend: 60000
tcpport: 7881
nodeip: YOURPUBLICIP
keys:
YOURAPIKEY: YOURAPISECRET
room:
autocreate: true
emptytimeout: 300
maxparticipants: 1000
logging:
level: info
sample: false
Replace
YOURPUBLICIP, YOURAPIKEY, and YOURAPISECRET with your actual values!Step 5: Create Docker Compose File
Create /opt/livekit/docker-compose.yml:
version: '3.9'
services:
livekit:
image: livekit/livekit-server:latest
containername: livekit
restart: unless-stopped
networkmode: host
command: --config /livekit.yaml
volumes:
./livekit-config.yaml:/livekit.yaml:ro
Step 6: Start LiveKit
cd /opt/livekit
docker compose up -d
Verify it's running
docker ps
docker logs livekit
Production Configuration
SSL/TLS Setup with Nginx
For production, LiveKit MUST be accessed via HTTPS/WSS for WebRTC to work in modern browsers.
Step 1: Install Nginx and Certbot
sudo apt install -y nginx certbot python3-certbot-nginx
Step 2: Create Nginx Configuration
Create /etc/nginx/sites-available/livekit:
# LiveKit WebRTC Streaming Proxy
Place in /etc/nginx/sites-available/livekit
upstream livekit {
server 127.0.0.1:7880;
}
server {
listen 80;
servername streaming.yourdomain.com;
# Redirect HTTP to HTTPS
return 301 https://$host$requesturi;
}
server {
listen 443 ssl http2;
servername streaming.yourdomain.com;
# SSL certificates (Let's Encrypt)
sslcertificate /etc/letsencrypt/live/streaming.yourdomain.com/fullchain.pem;
sslcertificatekey /etc/letsencrypt/live/streaming.yourdomain.com/privkey.pem;
# SSL settings
sslprotocols TLSv1.2 TLSv1.3;
sslpreferserverciphers on;
sslciphers XXXXX-XXXXX-AES128-XXX-SHA256:XXXXX-RSA-AES128-GCM-SHA256;
# LiveKit WebSocket proxy
location /livekit/ {
proxypass http://livekit/;
proxyhttpversion 1.1;
# WebSocket upgrade headers
proxysetheader Upgrade $httpupgrade;
proxysetheader Connection "upgrade";
# Standard proxy headers
proxysetheader Host $host;
proxysetheader X-Real-IP $remoteaddr;
proxysetheader X-Forwarded-For $proxyaddxforwardedfor;
proxysetheader X-Forwarded-Proto $scheme;
# Timeouts for long-lived connections
proxyreadtimeout 86400s;
proxysendtimeout 86400s;
# Disable buffering for real-time
proxybuffering off;
}
}
Step 3: Enable and Obtain SSL Certificate
# Enable site
sudo ln -s /etc/nginx/sites-available/livekit /etc/nginx/sites-enabled/
Test configuration
sudo nginx -t
Obtain SSL certificate
sudo certbot --nginx -d streaming.yourdomain.com
Restart Nginx
sudo systemctl restart nginx
PHP Configuration
Update config.inc.php
Add these lines to ct/dat/config.inc.php:
// =====================================================
// LiveKit WebRTC Streaming Configuration
// =====================================================
// LiveKit WebSocket URL
// Development: ws://YOURIP:7880
// Production: wss://streaming.yourdomain.com/livekit/
define('LIVEKITHOST', 'wss://streaming.yourdomain.com/livekit/');
// API credentials (from setup script)
define('LIVEKITAPIKEY', 'APIxxxxxxxxxxxxx');
define('LIVEKITAPISECRET', 'your-32-byte-secret-key-here');
Enable Live Streaming Feature
Navigate to Admin Panel → Settings → Feature Toggles and enable:
featurelivestreaming- Enable/Disable live streaming
Or add directly to the database:
INSERT INTO tblFeatureToggles (featurekey, featureenabled, featuregroup)
VALUES ('featurelivestreaming', 1, 'creatorfeatures')
ON DUPLICATE KEY UPDATE featureenabled = 1;
API Endpoints
The live streaming system provides these API endpoints:
Stream Management
Chat & Interactions
Access Control
Frontend Pages
Creator Broadcast Page (settings/golive.php)
Features:
- Webcam preview and selection
- Microphone selection
- Stream title and description
- Access type selection (free, password, subscribers, PPV, tip goal)
- Real-time chat panel
- Tip notifications
- Private request management
- Viewer count display
Access Requirements:
- User must be logged in
- User must have
iscreator = 1in tblCMSUsers featurelivestreamingmust be enabled
Viewer Page (watchstream.php)
Features:
- Live video player
- Real-time chat
- Tip sending
- Private show requests
- Viewer count
- Creator profile sidebar
Stream Directory (livestreams.php)
Features:
- Grid of active streams
- Viewer count badges
- Creator avatars
- Stream previews (snapshots)
- Filter by category
Testing Your Setup
Step 1: Verify LiveKit Server
# Check container status
docker ps | grep livekit
Check logs
docker logs livekit
Test WebSocket (should return error, which means it's responding)
curl http://localhost:7880
Expected: {"code":"InvalidArgument"...}
Step 2: Test from Browser Console
Open browser dev tools and run:
// Test WebSocket connection
const ws = new WebSocket('wss://streaming.yourdomain.com/livekit/');
ws.onopen = () => console.log('Connected to LiveKit');
ws.onerror = (e) => console.error('Connection error:', e);
Step 3: Test Full Workflow
Log in as a creator account
- Navigate to
settings/golive.php - Click "Go Live" to start broadcasting
- Open a second browser/incognito window
- Navigate to
livestreams.php - Click on your stream to watch
Common Tasks
Restarting LiveKit
# Restart container
docker restart livekit
Or full restart
docker compose down
docker compose up -d
Viewing Logs
# Real-time logs
docker logs -f livekit
Last 100 lines
docker logs --tail 100 livekit
Updating LiveKit
# Pull latest image
docker pull livekit/livekit-server:latest
Restart with new image
docker compose down
docker compose up -d
Checking Active Rooms
# Using LiveKit CLI (if installed)
livekit-cli list-rooms --url ws://localhost:7880 --api-key YOURKEY --api-secret YOURSECRET
Troubleshooting
Common Errors
Error: "LiveKit API key and secret must be configured"
Cause: LIVEKITAPIKEY or LIVEKITAPISECRET not defined in config.inc.php
Solution: Add the LiveKit configuration to your config.inc.php file:
define('LIVEKITHOST', 'wss://streaming.yourdomain.com/livekit/');
define('LIVEKITAPIKEY', 'your-api-key');
define('LIVEKITAPISECRET', 'your-api-secret');
Error: "WebSocket connection failed" or "Connection refused"
Cause: Firewall blocking ports or LiveKit not running
Solution:
- Verify LiveKit is running:
docker ps | grep livekit - Check firewall:
sudo ufw status - Open required ports:
sudo ufw allow 7880/tcp - Check Nginx proxy configuration
Error: "Only active creators can go live"
Cause: User doesn't have creator status
Solution:
- Check user has
iscreator = 1in tblCMSUsers - Check tblCreatorProfiles has an entry with
status = 'active'
Error: "Stream not connecting" (video not appearing)
Cause: Usually SSL/WSS mismatch or CORS issues
Solution:
- Ensure LIVEKITHOST uses
wss://for HTTPS sites - Check Nginx WebSocket headers are configured
- Verify SSL certificate is valid
- Check browser console for specific errors
Error: "Token expired" or authentication failures
Cause: Server time drift or incorrect API secret
Solution:
- Sync server time:
sudo ntpdate pool.ntp.org - Verify APISECRET matches in both config.yaml and config.inc.php
- Regenerate tokens by restarting stream
Debug Checklist
- LiveKit Container Running?
docker ps | grep livekit
- Ports Open?
sudo netstat -tlnp | grep -E '7880|7881'
- Config Values Match?
- Check
livekit-config.yamlAPI key/secret - Check
config.inc.phpAPI key/secret - They MUST be identical
- Nginx Proxying Correctly?
curl -v https://streaming.yourdomain.com/livekit/
- SSL Certificate Valid?
openssl sclient -connect streaming.yourdomain.com:443
Performance Tuning
For High Concurrent Viewers
Modify livekit-config.yaml:
# Increased limits for production
rtc:
portrangestart: 40000
portrangeend: 50000 # 10,000 ports for more viewers
room:
maxparticipants: 5000 # Increase from 1000
logging:
level: warn # Reduce logging overhead
Docker Resource Limits
Update docker-compose.yml:
services:
livekit:
image: livekit/livekit-server:latest
containername: livekit
restart: unless-stopped
networkmode: host
command: --config /livekit.yaml
volumes:
- ./livekit-config.yaml:/livekit.yaml:ro
deploy:
resources:
limits:
cpus: '4'
memory: 4G
reservations:
cpus: '2'
memory: 2G
Security Considerations
Live streaming involves real-time video - security is critical.
Best Practices
- Always use HTTPS/WSS in production
- WebRTC requires secure contexts in modern browsers
- Use Let's Encrypt for free SSL certificates
- Protect API credentials
- Never expose LIVEKITAPISECRET in frontend code
- Tokens are generated server-side only
- Implement rate limiting
- Prevent chat spam
- Limit stream start attempts
- Monitor for abuse
- Log stream metadata
- Review reported streams
- Firewall configuration
- Only open required ports
- Consider geo-blocking if needed
Related Documentation
- Live Streaming Implementation -
.docs/LIVESTREAMINGIMPLEMENTATION.md - LiveKit Setup Quick Start -
.docs/LIVEKITSETUP.md - Debian 12 Install Guide -
.docs/LIVEKITINSTALLDEBIAN12.md - Streaming Fixes -
.docs/LIVESTREAMINGFIXES.md - Setup Script -
tools/setuplivekitserver.sh
Translatable Strings
The following translation keys are used by the live streaming feature:
Install Script Checklist
- [ ] Docker installed and running
- [ ] Firewall ports opened (7880, 7881, 50000-51000) --- For the 50000-51000, this may need adjusted as opening so many ports not only a security issue, but it will cause the streaming server to fail on load.
- [ ] LiveKit configuration file created
- [ ] Docker Compose file created
- [ ] LiveKit container started
- [ ] API credentials added to config.inc.php
- [ ] Database migration 018 applied
- [ ] Database migration 019 applied (LiveKit fields)
- [ ] Nginx reverse proxy configured (production)
- [ ] SSL certificate obtained (production)
- [ ] Feature toggle enabled
- [ ] Test stream successful