DEV Community

Priyabrato Saha
Priyabrato Saha

Posted on

Deploying a LiveKit Server on Google Cloud VM โ€“ Step-by-Step Guide

๐Ÿš€ 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

  1. Go to GCP Console
  2. Navigate to Compute Engine > VM Instances
  3. Click Create Instance
  4. Settings:
  • Machine type: e2-medium or higher
  • Boot disk: Ubuntu 22.04 LTS
  • Firewall: Allow both HTTP and HTTPS
  • External IP: Static (Reserved)
    1. SSH into the instance:
gcloud compute ssh <instance-name> # or use browser SSH terminal 
Enter fullscreen mode Exit fullscreen mode

2. ๐Ÿงฑ Install Dependencies

sudo apt update && sudo apt upgrade -y sudo apt install -y tmux curl unzip nginx 
Enter fullscreen mode Exit fullscreen mode

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 
Enter fullscreen mode Exit fullscreen mode

Step 2: Create Config File (livekit.yaml)

nano livekit.yaml 
Enter fullscreen mode Exit fullscreen mode

Paste minimal config:

port: 7880 rtc: udp_port: 7881 tcp_port: 7882 keys: devkey: secret 
Enter fullscreen mode Exit fullscreen mode

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 
Enter fullscreen mode Exit fullscreen mode

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 
Enter fullscreen mode Exit fullscreen mode

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 
Enter fullscreen mode Exit fullscreen mode

5. ๐ŸŒ Configure NGINX (Optional: Reverse Proxy)

sudo nano /etc/nginx/sites-available/livekit 
Enter fullscreen mode Exit fullscreen mode

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; } } 
Enter fullscreen mode Exit fullscreen mode

Enable it:

sudo ln -s /etc/nginx/sites-available/livekit /etc/nginx/sites-enabled/ sudo nginx -t && sudo systemctl reload nginx 
Enter fullscreen mode Exit fullscreen mode

Optional: Add SSL with Let's Encrypt


6. โœ… Verify Everything

  • Visit http://<your-external-ip>:7880 or http://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 
Enter fullscreen mode Exit fullscreen mode

Happy hacking with LiveKit! ๐ŸŽ™๏ธ

Top comments (0)