๐ Setting up LiveKit Server on a Google Cloud VM (GCP)
This guide explains how to set up and run a LiveKit server on a Google Cloud VM instance using systemd
for persistent, auto-starting service.
๐ Prerequisites
- Google Cloud Project with billing enabled
- VM Instance created (preferably Ubuntu 22.04 LTS)
-
gcloud
CLI configured (optional for local management) - Domain name (optional but useful)
1. โ Create and Configure a VM Instance
- Go to GCP Console
- Navigate to Compute Engine > VM Instances
- Click Create Instance
- Settings:
- Machine type: e2-medium or higher
- Boot disk: Ubuntu 22.04 LTS
- Firewall: Allow both HTTP and HTTPS
- External IP: Static (Reserved)
- SSH into the instance:
gcloud compute ssh <instance-name> # or use browser SSH terminal
2. ๐งฑ Install Dependencies
sudo apt update && sudo apt upgrade -y sudo apt install -y tmux curl unzip nginx
3. ๐ Install and Set Up LiveKit Server
Step 1: Download the Binary
cd ~ mkdir -p apps/livekit && cd apps/livekit curl -LO https://github.com/livekit/livekit/releases/latest/download/livekit-linux-amd64 chmod +x livekit-linux-amd64 sudo mv livekit-linux-amd64 /usr/local/bin/livekit-server
Step 2: Create Config File (livekit.yaml
)
nano livekit.yaml
Paste minimal config:
port: 7880 rtc: udp_port: 7881 tcp_port: 7882 keys: devkey: secret
Replace keys with your preferred API key pair or manage with env vars.
4. โ๏ธ Set Up systemd
Service
sudo nano /etc/systemd/system/livekit.service
Paste the following:
[Unit] Description=LiveKit Server After=network.target [Service] ExecStart=/usr/local/bin/livekit-server --config /home/YOUR_USER/apps/livekit/livekit.yaml Restart=always User=YOUR_USER WorkingDirectory=/home/YOUR_USER/apps/livekit [Install] WantedBy=multi-user.target
Replace
YOUR_USER
with your GCP username (e.g.,priya_scse2022
)
Reload and Enable
sudo systemctl daemon-reexec sudo systemctl daemon-reload sudo systemctl enable livekit.service sudo systemctl start livekit.service sudo systemctl status livekit.service
5. ๐ Configure NGINX (Optional: Reverse Proxy)
sudo nano /etc/nginx/sites-available/livekit
Paste:
server { listen 80; server_name livekit.yourdomain.com; location / { proxy_pass http://localhost:7880; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $host; } }
Enable it:
sudo ln -s /etc/nginx/sites-available/livekit /etc/nginx/sites-enabled/ sudo nginx -t && sudo systemctl reload nginx
Optional: Add SSL with Let's Encrypt
6. โ Verify Everything
- Visit
http://<your-external-ip>:7880
orhttp://livekit.yourdomain.com
- Check logs:
journalctl -u livekit.service -f
- On VM reboot, LiveKit will auto-start via
systemd
โ Done!
You now have a persistent, production-ready LiveKit server running on GCP with automatic restarts using systemd
and optional reverse proxy using NGINX.
๐ก Pro Tips
- Add a firewall rule to open ports
7880-7882
- Use
ufw
or GCP firewall for tighter security - For production, consider load balancing and TLS termination
- To update LiveKit:
sudo systemctl stop livekit.service curl -LO https://github.com/livekit/livekit/releases/latest/download/livekit-linux-amd64 chmod +x livekit-linux-amd64 sudo mv livekit-linux-amd64 /usr/local/bin/livekit-server sudo systemctl start livekit.service
Happy hacking with LiveKit! ๐๏ธ
Top comments (0)