-
Easily Start a Localtunnel for Your DDEV Sites
Every time I needed a public tunnel for local development, I was repeating the same handful of steps. Localtunnel is a great free alternative to ngrok, and it deserves a proper DDEV command. Follow the steps to make one:
Step 1: Create this file in your project’s directory: .ddev/commands/host/localtunnel
123456789101112131415161718192021222324#!/usr/bin/env bash## Description: Start a localtunnel for this DDEV project## Usage: lt [subdomain]## Example: ddev lt myname-mysiteset -eSUBDOMAIN=${1:-${DDEV_SITENAME}}# Get the HTTPS host port from dockerPORT=$(docker inspect "ddev-${DDEV_SITENAME}-web" \--format '{{range $p, $conf := .NetworkSettings.Ports}}{{if eq $p "80/tcp"}}{{(index $conf 0).HostPort}}{{end}}{{end}}')if [ -z "$PORT" ]; thenecho "Could not determine HTTPS port for ${DDEV_SITENAME}. Is DDEV running?"exit 1fiecho "Starting localtunnel for ${DDEV_SITENAME} on port ${PORT}..."echo "Subdomain: https://${SUBDOMAIN}.loca.lt"echo ""lt --port="${PORT}" --local-host "127.0.0.1" --subdomain="${SUBDOMAIN}"Step 2: chmod +x .ddev/commands/host/localtunnel
Step 3: Use it like this: ddev lt adam-mysite
Of course, this will only work if you have localtunnel installed ( brew install localtunnel ).
When you run the command it’ll show you the resulting URL (e.g., https://adam-mysite.local.lt).
When finished, hit CTRL-C (on a Mac, at least) to close the session.