Skip to content

Conversation

@USERSATOSHI
Copy link
Contributor

@USERSATOSHI USERSATOSHI commented Aug 1, 2025

What?

Closes #23947, #65008

Why?

Currently the wp-env site is set to localhost address, so trying to map the site to the likes of an ngrok external domain just results in a redirect back to localhost.(#23947)

This PR adds support for that by dynamically defining the WP_HOME and WP_SITEURL via the snippet sent by @glendaviesnz.

Alongside this PR also adds support for setting WP_HOME and WP_SITEURL via env variables to allow for cases where the url is generated dynamically like gitpod.

How?

This PR solves this by adding WP_ENV_DYNAMIC_URLS_ENABLED env var ( default to true ) which enables dynamically defining WP_HOME and WP_SITEURL constants.
This PR also adds WP_ENV_HOMEURL , WP_ENV_SITEURL for development environment and WP_ENV_TESTS_HOMEURL , WP_ENV_TESTS_SITEURL for tests environment.

to disable dynamically defining , pass WP_ENV_DYNAMIC_URLS_ENABLED=false when running wp-env start.

Testing Instructions

_
  1. run npm run wp-env start -- --update
  2. run a tunnel ( npx localtunnel -p 8888 )
  3. open the tunnel domain
  4. see the site working as normal.

Screenshots or screencast

npm run wp-env start -- --update

image image

WP_ENV_DYNAMIC_URLS_ENABLED=false npm run wp-env start -- --update

image

WP_ENV_SITEURL & WP_ENV_HOMEURL support

image

cmd: WP_ENV_HOMEURL="https://tricky-boats-post.loca.lt" WP_ENV_SITEURL="https://tricky-boats-post.loca.lt" npm run wp-env start -- --debug --update

Note: --update is required because it needs to write to wp-config.php.

- This commits adds support dynamically defining urls which is useful when using reverse proxy like ngrok, localtunnel etc
- This is enabled by default and can be disabled by using WP_ENV_DYNAMIC_URLS_ENABLED=false when using wp-env start
- This commits also add support settings WP_HOME and WP_SITEURL via env variables
@USERSATOSHI
Copy link
Contributor Author

USERSATOSHI commented Aug 1, 2025

Trying to figure out why setting url via env is causing
~~ ~~⠙ Configuring WordPress.Error: This does not seem to be a WordPress installation.~~ ~~The used path is: /var/www/html/~~ ~~Pass --path=`path/to/wordpress` or run `wp core download`.~~ ~~⠹ Configuring WordPress.exit status 1~~ ~~⠸ Configuring WordPress. Container 23f76220ed5a7267362fb06fbba395ea-mysql-1 Running~~ ~~ Container 23f76220ed5a7267362fb06fbba395ea-wordpress-1 Running~~ ~~

If I figure it out, then I will add the fix else, I will remove the env support. I believe that dynamically defining should also partially fix issue #65008

UPDATE: fixed the issue by changing the env from WP_ENV_HOME to WP_ENV_HOMEURL, didn't realize, it was being used for WordPress installation.

@yogeshbhutkar yogeshbhutkar added [Type] Enhancement A suggestion for improvement. [Tool] Env /packages/env labels Aug 5, 2025
- changed WP_HOME env to WP_ENV_HOMEURL to prevent conflict with WP_ENV_HOME
- updated start cmd to reflect env value
@USERSATOSHI USERSATOSHI marked this pull request as ready for review August 5, 2025 09:43
@github-actions
Copy link

github-actions bot commented Aug 5, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @apeatling, @jdmwood.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Unlinked contributors: apeatling, jdmwood.

Co-authored-by: USERSATOSHI <[email protected]>
Co-authored-by: Mwalek <[email protected]>
Co-authored-by: glendaviesnz <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@manzoorwanijk manzoorwanijk changed the title Add support for dynamic URLs and allow setting WP_HOME and WP_SITEURL via env variables env: Add support for dynamic URLs and allow setting WP_HOME and WP_SITEURL via env variables Aug 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Tool] Env /packages/env [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wp-env: Make site site and home url dynamic

2 participants