Share a local WordPress site
Share a local WordPress site through a Horizon tunnel, and stop it redirecting to localhost by setting WP_HOME and WP_SITEURL.
Show a WordPress site running on your laptop at https://my-app.hrzn.run, with links, assets and redirects that point at the public URL.
WordPress stores siteurl and home in its database. Both hold http://localhost:8080 or similar, so the site redirects visitors to localhost. You fix that by overriding them.
Before you begin
- Node.js 18 or later
- A Horizon account and the CLI (see Getting started)
- A reserved subdomain for
-s. Reserve one on the Subdomains page. - A local WordPress site, and access to its
wp-config.php
Start a tunnel
Use the port your local WordPress listens on. This guide uses 8080. Use -s with a subdomain you reserved. Without it, the subdomain is random and changes every run, and you would change the WordPress URL each time. Reserved subdomains are a paid feature, see Pricing.
hrzn tunnel http://localhost:8080 -s my-appHORIZON: Tunnel connected
URL https://my-app.hrzn.run (reserved)
Forwarding http://localhost:8080
Request log https://hrzn.run/dashboard/tunnels/my-appSet WP_HOME and WP_SITEURL
Add both constants to wp-config.php. WordPress's docs say they override the home and siteurl values in the database without changing the database. Include https:// and leave out the trailing slash.
define( 'WP_HOME', 'https://my-app.hrzn.run' );
define( 'WP_SITEURL', 'https://my-app.hrzn.run' );WordPress's migration guide warns that this hard-codes the values. You can't edit them on the General settings page while the constants exist. Remove the constants when you stop sharing.
If you want the database values to change, use WP-CLI instead:
wp option update home 'https://my-app.hrzn.run'
wp option update siteurl 'https://my-app.hrzn.run'Pick the constants for a short share, because you can delete them in one edit. Pick WP-CLI when the new URL stays.
Tell WordPress it is on HTTPS
The tunnel serves HTTPS, but your local WordPress receives plain HTTP. WordPress's HTTPS guide shows how to set $_SERVER['HTTPS'] to on in wp-config.php when a proxy provides SSL. Its example checks for https anywhere in the X-Forwarded-Proto value, because that header can hold a list such as https,http. Horizon appends to that header, so use the check as written. Don't compare the header to the string https.
if ( strpos( $_SERVER['HTTP_X_FORWARDED_PROTO'], 'https' ) !== false ) {
$_SERVER['HTTPS'] = 'on';
}The guide pairs this with FORCE_SSL_ADMIN. Leave FORCE_SSL_ADMIN out unless you need it.
Fix hard-coded http URLs
Your tunnel serves HTTPS. A page loaded over HTTPS that requests an http:// image or script has mixed content, and browsers block or warn about it. Post content, widgets and theme settings can store absolute http://localhost:8080 URLs in the database. The constants don't change those. Replace them with WP-CLI, which WordPress's migration guide shows with --skip-columns=guid:
wp search-replace 'http://localhost:8080' 'https://my-app.hrzn.run' --skip-columns=guidRun it with --dry-run first to see what changes. This rewrites your local database, so back it up first.
Check it works
Open https://my-app.hrzn.run in a browser. The first visit shows Before you continue. Select Continue to site. Your home page loads, the address bar stays on my-app.hrzn.run and images load. Your Horizon terminal prints lines like:
GET 200 /Troubleshooting
The site redirects to localhost
WordPress still uses the home and siteurl stored in the database. Check that both constants are in wp-config.php and that you saved the file. Check that they hold https://my-app.hrzn.run.
Images or styles are missing, and the console shows mixed content
Something still requests an http:// URL. Open your browser's developer console to find the URL, then run the wp search-replace command for it.
The page redirects in a loop
WordPress's docs say that behind a proxy that provides SSL, FORCE_SSL_ADMIN can send requests into an infinite redirect loop. Add the $_SERVER['HTTPS'] block from the step above, or remove FORCE_SSL_ADMIN from wp-config.php.
The URL changed after a restart
You started the tunnel without -s, so Horizon gave you a new random subdomain. Restart with -s my-app and the URL stays the same. -s needs a subdomain you reserved, see Pricing.
Next steps
- Read WordPress's guide to migrating and changing the site URL.
- Read the
wp-config.phpreference.
Reach Home Assistant from outside your network
Reach Home Assistant from outside your network with a Horizon tunnel, with WebSocket passthrough, reverse proxy settings and the external URL.
Host a web app behind CGNAT or Starlink
Host a web app from home behind CGNAT or Starlink with an outbound Horizon tunnel, when port forwarding isn't possible.