Connecting Local Valet Site to JetPack
Some Jetpack features, such the Instagram oEmbed provider, are only available to sites with an active connection to Jetpack. A local Valet site can be connected to Jetpack by tunneling traffic though Ngrok. This setup requires changing Valet's TLD if using a free account, which "switches" your entire local environment to work with only the site being connected to Jetpack until it's switched back.
⚠️
With a default/free Ngrok configuration, the tunnel makes the local site publicly accessible. Do not tunnel unauthenticated traffic to your local site if it contains any real drafts, not-for-publish posts, production user data, or any other sensitive information.
Installation
- Back up your Valet Nginx server blocks at
~/.config/valet/Nginx, just in case changing Valet's TLD causes an unwanted loss of configuration - Sign up for Ngrok (opens in a new tab)
- Install Ngrok (opens in a new tab) (Homebrew is suggested)
- Go to your Ngrok Dashboard (opens in a new tab) and add a static domain in Cloud Edge → Domains (opens in a new tab)
Enabling Jetpack on a site
- Set your local Valet-hosted site's domain to the static Ngrok domain:
cdto your "parked" sites directory (ex:cd ~/pmc/sites)- Rename the directory of the site you want to connect to Jetpack to match the static Ngrok domain (ex:
mv rollingstone ohi-marc.ngrok-free.app) - Switch the target site's URL in the database. Ex:
cd rollingstone && wp search-replace https://rollingstone.test https://ohi-marc.ngrok-free.app
- Switch Valet's top-level domain from
testto the Ngrok static domain withvalet domain app(appbeing the domain). This will reset all of your Valet Nginx server blocks, wiping out any custom configurations. The Nginx site configuration injection script can be used to restore those values, though. If you have a paid account that can configure a.testdomain, this step is not required. - Get the Nginx site configuration injection script and set
gltdto match the static Ngrok domain (ex:testtoapp). - Execute the Nginx configuration injection script
- Start the Ngrok tunnel. Ex:
ngrok http --domain=ohi-marc.ngrok-free.app ohi-marc.ngrok-free.app:443 - Visit the domain and connect the site to Jetpack in the WordPress admin
Restoring Valet back to .test
- Kill the Ngrok tunnel if it's still running
- Switch Valet's top-level domain back to
.testwithvalet domain test - Set the Nginx configuration injection script's
gltdback totestand execute it - Switch your local site directory and database URLs back to the
.testdomain