Loading...

Self-hosting Langflow on an Ubuntu Server

Jonas Scholz - Co-Founder von sliplane.ioJonas Scholz
7 min

Want to build powerful AI workflows using Langflow but prefer to fully control your infrastructure? By self-hosting Langflow on a Linux Ubuntu server, you can cut down costs and manage your data yourself!

Follow along this easy-to-understand guide to learn how you can deploy your own Langflow instance using Docker and Caddy Web server for automatic HTTPS.

Before we start, make sure you have:

  • a running Ubuntu Linux server instance. A good option is Hetzner, but any Ubuntu server that you can login to with SSH and that has a public IP address works.
  • basic SSH experience.

Step 1: Update Your Server

Log into your Ubuntu server via SSH and update the system to ensure it has the latest security patches and updates.

sudo apt-get update
sudo apt-get upgrade -y

Once finished, your server is ready for installing the software.

Step 2: Install and Configure UFW Firewall

Only keep necessary ports open: SSH (22), HTTP (80), HTTPS (443).

Install UFW and configure the firewall as follows:

sudo apt install ufw -y
sudo ufw allow 22    # SSH
sudo ufw allow 80    # HTTP
sudo ufw allow 443   # HTTPS
sudo ufw enable

Check your firewall configuration:

sudo ufw status verbose

Note: Docker can sometimes ignore UFW rules. To tackle this, verify extra settings as explained here.

Step 3: Docker Installation

Docker will be the container system running Langflow. Install Docker by running these commands:

Setup dependencies and Docker's GPG key:

sudo apt-get update
sudo apt-get install ca-certificates curl gnupg

sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg \
| sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /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/ubuntu \
$(. /etc/os-release && echo $VERSION_CODENAME) stable" \
| sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt-get update

Install Docker Engine and compose-plugin:

sudo apt-get install docker-ce docker-ce-cli \
containerd.io docker-buildx-plugin docker-compose-plugin -y

Check installation:

sudo docker run hello-world

If you see the "hello-world" message, Docker is ready.

Step 4: Installing Caddy for Automatic HTTPS

Caddy simplifies HTTPS configuration since it handles SSL certificates automatically from Let's Encrypt.

Install Caddy:

sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl

curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' \
| sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg

curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' \
| sudo tee /etc/apt/sources.list.d/caddy-stable.list

sudo apt update
sudo apt install caddy -y

Edit the Caddyfile configuration file:

sudo nano /etc/caddy/Caddyfile

Enter your domain and configure reverse proxy. Replace "yourdomain.com" with your actual domain name:

yourdomain.com {
    reverse_proxy localhost:7860
}

If no domain yet, use this temporarily:

:80 {
    reverse_proxy localhost:7860
}

Restart Caddy to load the config:

sudo systemctl restart caddy

Step 5: Running Langflow with Docker Compose

We're going to use Docker Compose for easier setup. First create a directory for Langflow and navigate to it:

mkdir ~/langflow
cd ~/langflow

SQLite Configuration (Simple Setup)

Create compose.yml with the following content for SQLite database:

services:
  langflow:
    image: docker.io/langflowai/langflow:latest
    restart: always
    ports:
      - "7860:7860"
    environment:
      - LANGFLOW_HOST=0.0.0.0
      - LANGFLOW_CONFIG_DIR=/app/langflow
      - LANGFLOW_SUPERUSER=admin
      - LANGFLOW_SUPERUSER_PASSWORD=change_me_to_secure_password
      - LANGFLOW_SECRET_KEY=your_secret_key_here
      - DO_NOT_TRACK=true
      - LANGFLOW_AUTO_LOGIN=false
    volumes:
      - langflow_data:/app/langflow

volumes:
  langflow_data:

PostgreSQL Configuration (Production Setup)

For production environments, PostgreSQL is recommended. Create compose.yml with the following content:

services:
  postgres:
    image: docker.io/library/postgres:16.4
    restart: always
    environment:
      - POSTGRES_USER=langflow
      - POSTGRES_PASSWORD=your_postgres_password
      - POSTGRES_DB=langflow
    volumes:
      - postgres_data:/var/lib/postgresql/data
    ports:
      - "5432:5432"

  langflow:
    image: docker.io/langflowai/langflow:latest
    restart: always
    ports:
      - "7860:7860"
    environment:
      - LANGFLOW_HOST=0.0.0.0
      - LANGFLOW_CONFIG_DIR=/app/langflow
      - LANGFLOW_SUPERUSER=admin
      - LANGFLOW_SUPERUSER_PASSWORD=change_me_to_secure_password
      - LANGFLOW_SECRET_KEY=your_secret_key_here
      - DO_NOT_TRACK=true
      - LANGFLOW_AUTO_LOGIN=false
      - DATABASE_URL=postgresql://langflow:your_postgres_password@postgres:5432/langflow
    volumes:
      - langflow_data:/app/langflow
    depends_on:
      - postgres

volumes:
  langflow_data:
  postgres_data:

Important: Replace your_postgres_password, change_me_to_secure_password, and your_secret_key_here with secure values before deployment.

Now deploy Langflow by running Docker compose:

sudo docker compose up -d

Docker pulls the Langflow image and runs it in background mode using port 7860.

Step 6: Accessing Your Self-Hosted Langflow Instance

Visit your domain in any web browser. Your Langflow instance should now load successfully at https://yourdomain.com. Log in with the superuser credentials you configured to complete your initial setup.

Langflow dashboard

Security Recommendations

Public servers should always be secure. The following practises are recommended:

  • Regularly apply updates and security patches.
  • Set strong passwords and control user access.
  • Monitor server logs for suspicious activity.
  • Install tools like Fail2ban for extra security.
  • Use environment variables for secrets instead of hardcoding them.

Updating your Langflow Installation

When you want to update your Langflow instance, simply run:

sudo docker compose pull
sudo docker compose up -d

Docker will download updated versions automatically and replace your current containers.

Cost Comparison with Other Providers

Self-hosting Langflow typically results in lower cost compared to hosted services:

ProvidervCPURAMDiskMonthly Cost
Render.com12 GB40 GB~$35
Fly.io22 GB40 GB~$17–20
Railway22 GB40 GB~$15–30
Sliplane.io22 GB40 GB~€9.50 flat
Hetzner Cloud (self-hosted)22 GB40 GB~€5–10 / month

You maintain complete control and avoid additional usage-based charges by self-hosting. But of course there is no free lunch and you're now responsible for managing your own server!

Is anything missing with a self-hosted Langflow?

Self-hosted Langflow provides the full open-source experience with all features available. You can build complex AI workflows, integrate with various APIs and models, and customize everything according to your needs.

Now you have your own self-hosted Langflow instance running on Ubuntu! Time to start building your AI workflows.

If managing and securing your own server is a bit too much for you, check out how easy it is to deploy a managed instance of Langflow on sliplane (takes 45 seconds!)

Welcome to the container cloud

Sliplane makes it simple to deploy containers in the cloud and scale up as you grow. Try it now and get started in minutes!