Raised: $0
0% of monthly goal Help us cross the finish line!
Goal: $12,000
Raised: $0 Goal: $12,000
0% of monthly goal Help us cross the finish line!
Sponsor DDEV

ddev-share-cf

Share your DDEV sites publicly using Cloudflare Tunnel (free alternative to ddev share)

version license DDEV registry](https://github.com/ddev/ddev-addon-registry)

What is this?

This DDEV addon provides a simple command to share your local DDEV sites publicly using Cloudflare Tunnel. It works similarly to ddev share (which uses ngrok) but with Cloudflare’s free tunnel service.

Features

Requirements

Important for Windows users: This addon requires WSL2. You must install and run DDEV in WSL2, not natively on Windows. See the WSL2 section below for details.

Installation

1. Install cloudflared

First, install cloudflared on your host machine:

macOS (Homebrew):

brew install cloudflared

Debian/Ubuntu:

curl -L https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb -o cloudflared.deb
sudo dpkg -i cloudflared.deb

RHEL/CentOS/Fedora:

curl -L https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.rpm -o cloudflared.rpm
sudo rpm -i cloudflared.rpm

Windows with WSL2:

Important: This addon requires WSL2. WSL2 is your “host” environment where both DDEV and cloudflared must be installed.

If you’re using DDEV with WSL2 (the recommended approach for Windows), follow the Linux instructions above inside your WSL2 terminal. For example, if using Ubuntu in WSL2:

# Run this inside your WSL2 terminal (not PowerShell or CMD)
curl -L https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb -o cloudflared.deb
sudo dpkg -i cloudflared.deb

Do NOT install cloudflared on Windows itself - it needs to be installed in WSL2 where DDEV runs.

For other installation methods, see the Cloudflare documentation.

2. Install the DDEV addon

ddev add-on get davo20019/ddev-share-cf

Usage

From your DDEV project directory, simply run:

ddev share-cf

This will:

  1. Check if cloudflared is installed (shows installation instructions if not)
  2. Start a Cloudflare Tunnel
  3. Display a public URL you can share (like https://randomly-generated.trycloudflare.com)

Press Ctrl+C to stop the tunnel when you’re done.

How It Works

When you run ddev share-cf, the addon:

  1. Verifies cloudflared is installed on your host machine
  2. Creates a temporary Cloudflare Tunnel pointing to your DDEV site
  3. Routes public traffic through Cloudflare’s network to your local DDEV site
  4. No Cloudflare account or configuration required

The tunnel URL changes each time you run the command (similar to ddev share).

Comparison with ddev share

Feature ddev share (ngrok) ddev share-cf (Cloudflare)
Free tier 40 connections/min Unlimited
Speed Good Excellent (Cloudflare CDN)
Account required Yes No
Setup Configure token Zero config
URL persistence Changes each time Changes each time (or stable with named tunnels)

Named Tunnels (Stable URLs)

By default, ddev share-cf creates a temporary quick tunnel with a random URL that changes each time. If you need a stable, persistent URL on your own domain, you can use named tunnels.

Requirements for named tunnels

Don’t have a domain in Cloudflare? No problem — quick tunnels (ddev share-cf with no flags) work without any account or domain. Named tunnels are only needed if you want a stable URL on your own domain.

Setup (one-time)

1. Authenticate with Cloudflare

ddev share-cf --login

This opens your browser to authorize cloudflared with your Cloudflare account. A certificate is saved to ~/.cloudflared/cert.pem.

2. Create a tunnel and DNS route

ddev share-cf --create-tunnel my-project --hostname dev.example.com

This creates a named tunnel and adds a CNAME record on your Cloudflare domain pointing to the tunnel. DNS propagation may take a few minutes.

You can also create the tunnel without a hostname and add DNS later:

ddev share-cf --create-tunnel my-project

Daily usage

Once set up, start the tunnel with:

ddev share-cf --tunnel my-project

Your site will be available at https://dev.example.com (or whatever hostname you configured) every time.

Cleanup

To delete a named tunnel:

ddev share-cf --delete-tunnel my-project

Note: This deletes the tunnel from Cloudflare but does not remove the DNS record. You can remove CNAME records from the Cloudflare dashboard.

Named tunnels vs quick tunnels

  Quick tunnel Named tunnel
URL Random *.trycloudflare.com Your own domain
Persistence Changes each time Stable across sessions
Account Not required Cloudflare account + domain
Setup None One-time login + create
Best for Quick demos, testing Webhooks, client previews, CI

Use Cases

Perfect for:

Troubleshooting

Windows/WSL2: cloudflared not found

If you’re using Windows with WSL2 and getting a “cloudflared not found” error:

  1. Verify you’re in WSL2: Open your WSL2 terminal (Ubuntu, Debian, etc.) - not PowerShell or CMD
  2. Install cloudflared in WSL2: Follow the Linux installation instructions in your WSL2 terminal:
    curl -L https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb -o cloudflared.deb
    sudo dpkg -i cloudflared.deb
    
  3. Run all DDEV commands in WSL2: Both ddev and ddev share-cf must be run from your WSL2 terminal

Common mistake: Installing cloudflared on Windows (via winget or PowerShell) instead of in WSL2. Remember: WSL2 is your “host” environment, not Windows.

cloudflared not found (macOS/Linux)

If you get an error that cloudflared is not installed, the command will automatically detect your operating system and show you the appropriate installation instructions.

You can also manually install cloudflared by following the instructions in the Installation section above.

Command not found after installation

Make sure the addon is properly installed:

ddev add-on get davo20019/ddev-share-cf

Permission denied error

The script should be executable, but if you encounter issues:

chmod +x .ddev/commands/host/share-cf

Project not running

Make sure your DDEV project is running before starting the tunnel:

ddev start
ddev share-cf

Drupal Multisite Configuration

The addon automatically detects Drupal multisite setups by checking for sites/sites.php. When detected, it adjusts the tunnel configuration to properly support multisite routing.

To use with Drupal multisite:

  1. Run ddev share-cf - it will detect multisite and display: ℹ️ Drupal multisite detected
  2. Note the generated URL (e.g., https://random-name.trycloudflare.com)
  3. Add the mapping to your web/sites/sites.php:
<?php
// Map the Cloudflare tunnel URL to your subsite
$sites['random-name.trycloudflare.com'] = 'stage';  // Replace 'stage' with your subsite directory name
  1. The tunnel will now correctly route to your subsite

Note: The tunnel URL changes each time you run the command, so you’ll need to update sites.php with the new URL for each session.

WordPress URL Redirects

The addon automatically detects WordPress installations. WordPress stores absolute URLs throughout the database (options, post content, meta fields, serialized data, etc.), which causes redirects, broken media, and broken links when accessing the site through a tunnel URL.

When WordPress is detected, the addon will display instructions. To fix this, use wp search-replace to replace URLs across all tables (including serialized data):

  1. Run ddev share-cf and note the generated URL (e.g., https://random-name.trycloudflare.com)
  2. Replace all URLs in the database:
# Replace local URL with tunnel URL (handles serialized data correctly)
ddev wp search-replace 'https://yoursite.ddev.site' 'https://random-name.trycloudflare.com' --all-tables
  1. When done, revert back to local URLs:
# Revert to local domain
ddev wp search-replace 'https://random-name.trycloudflare.com' 'https://yoursite.ddev.site' --all-tables

Note: The tunnel URL changes each time you run the command, so you’ll need to repeat this for each session.

Magento Base URL Redirects

The addon automatically detects Magento installations. Like WordPress, Magento stores base URLs in the database (core_config_data table), which causes redirects (like admin login) to redirect back to your local domain.

When Magento is detected, the addon will display instructions. To fix redirects:

  1. Run ddev share-cf and note the generated URL (e.g., https://random-name.trycloudflare.com)
  2. Update Magento base URLs:
# Update to tunnel URL (include trailing slash)
ddev exec bin/magento config:set web/unsecure/base_url 'https://random-name.trycloudflare.com/'
ddev exec bin/magento config:set web/secure/base_url 'https://random-name.trycloudflare.com/'
ddev exec bin/magento cache:flush
  1. When done, revert back to local URLs:
# Revert to local domain
ddev exec bin/magento config:set web/unsecure/base_url 'https://yoursite.ddev.site/'
ddev exec bin/magento config:set web/secure/base_url 'https://yoursite.ddev.site/'
ddev exec bin/magento cache:flush

Note: The tunnel URL changes each time you run the command, so you’ll need to update the base URLs for each session.

Contributing

Contributions, issues, and feature requests are welcome!

License

Apache License 2.0 - see LICENSE file for details.

Maintainer

David Loor

Acknowledgments