Public tunnel
A remote development environment runs the PHP webserver on the localhost of a remote machine, which your own browser can't reach. Codespaces, DevPod, a remote Docker host and an SSH dev box all work this way. The tooling can expose the webserver through a Cloudflare quick tunnel, a public *.trycloudflare.com HTTPS URL that needs no account, DNS or configuration. This page covers turning the tunnel on, what it changes and opening the site on a phone.
While the tunnel is up, the site is on the public internet. A local Drupal site usually has a known admin account and no firewall. Use disposable test data only, and stop the tunnel with stop when you're done.
Turn on the tunnel
To turn on the tunnel:
- Install
cloudflaredso it's on yourPATH. - Set
CLOUDFLARE_TUNNEL=1in.envor in your shell. - Build the site. On a site you've already built, run
startand thenprovisionin place ofbuild.
The following commands set the variable in your shell, then build:
- Make
- Ahoy
- No wrapper
export CLOUDFLARE_TUNNEL=1
make build
export CLOUDFLARE_TUNNEL=1
ahoy build
export CLOUDFLARE_TUNNEL=1
scripts/eddy-tooling
vendor/bin/eddy-assemble
vendor/bin/eddy-start
vendor/bin/eddy-provision
Confirm that the tunnel is up: provision prints a *.trycloudflare.com address as the site URL, and info prints the same address.
The tunnel stays off for an empty value and for 0, false, no and off, in any letter case. Any other value, such as 1, turns it on. A value in your shell wins over .env. An empty shell value counts as unset, so .env decides. To override a .env that turns the tunnel on, set 0, false, no or off in your shell. For a single command, prefix it, such as CLOUDFLARE_TUNNEL=0 make start.
What happens
The tunnel changes what these commands do:
startstarts a tunnel and writes its URL to.envasTUNNEL_URL. It reuses a running tunnel that forwards to the same port and whose URL still answers. Withoutcloudflared, or when no URL appears within 30 seconds,startcarries on without the tunnel and says so.provisionadds the reverse-proxy and trusted-host settings that Drupal needs behind the tunnel tosettings.php.start,provision,info,drushandloginuse the tunnel URL as the site URL.stopcloses the tunnel and removes its URL from.env, even whileCLOUDFLARE_TUNNELis off. It leavesCLOUDFLARE_TUNNELas it is.resetcloses it too, and so doesassemblewhen it stops a running webserver.
After you turn CLOUDFLARE_TUNNEL off, a running tunnel stays up, and the site public, until the next stop. To close the tunnel, run the following command:
- Make
- Ahoy
- No wrapper
make stop
ahoy stop
vendor/bin/eddy-stop
When a tunnel doesn't come up, read .logs/cloudflared.log in the project root, where cloudflared writes its output.
Bring your own tunnel
The commands treat any TUNNEL_URL in .env as the site URL, whichever tool wrote it. To use a different tunnel, such as ngrok, start it from a lifecycle script like scripts/start-ngrok.sh and write its URL to .env. Keep CLOUDFLARE_TUNNEL off. With it on, provision adds trusted-host settings that accept only the Cloudflare and local hosts. 2 things work only with the Cloudflare tunnel:
provisionadds itssettings.phpentries for a Cloudflare tunnel only. Behind another tunnel, add the settings that tunnel needs tosettings.phpyourself, such asreverse_proxy, so Drupal detects HTTPS.stopremoves only a*.trycloudflare.comURL from.env, so remove your tunnel's URL from astop-*.shscript.
Open the site on a phone
vendor/bin/eddy-qrcode <url> draws any URL as a QR code in the terminal, so you can open the URL by scanning the code with a phone. It needs qrencode on PATH. To draw the site URL, run the following command:
vendor/bin/eddy-qrcode "$(vendor/bin/eddy-info site-url)"
To have login draw the one-time login link as a QR code too, set LOGIN_QRCODE=1 in .env or your shell (see Log in).