π 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)
-
gcloudCLI 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_USERwith 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>:7880orhttp://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
ufwor 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)