-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Closed
Labels
[Status] Needs More InfoFollow-up required in order to be actionable.Follow-up required in order to be actionable.[Tool] Env/packages/env/packages/env
Description
Propose to add something like the follows in README.md to make this more explicit.
Internet access
By default, wp-env does not have access to the Internet. You can get around this by adding the following to wp-config.php:
defined( 'WP_PROXY_HOST' ) or define( 'WP_PROXY_HOST', 'socks://host.docker.internal' );
defined( 'WP_PROXY_PORT' ) or define( 'WP_PROXY_PORT', '8080' );A shortcut command to achieve that:
$ wp-env run cli -- sh -c 'echo -e "\ndefined( '\''WP_PROXY_HOST'\'' ) or define( '\''WP_PROXY_HOST'\'', '\''socks://host.docker.internal'\'' );\ndefined( '\''WP_PROXY_PORT'\'' ) or define( '\''WP_PROXY_PORT'\'', '\''8080'\'' );" | tee -a wp-config.php'Example scenario
Install wp-env:
$ npm -g i @wordpress/env
...
$ wp-env start
...Try making a request to the Internet (only WP.org works):
$ wp-env run cli wp shell
ℹ Starting 'wp shell' on the cli container. Exit the WordPress shell with ctrl-c.
wp> wp_remote_retrieve_body( wp_remote_get( 'https://woocommerce.com/wp-json/helper/1.0/oauth/authorize' ) )
=> string(0) ""
wp> wp_remote_retrieve_body( wp_remote_get( 'https://wordpress.org' ) )
=> string(144732) "<!DOCTYPE html>...
Add the following lines to wp-config.php:
defined( 'WP_PROXY_HOST' ) or define( 'WP_PROXY_HOST', 'socks://host.docker.internal' );
defined( 'WP_PROXY_PORT' ) or define( 'WP_PROXY_PORT', '8080' );$ wp-env run cli -- sh -c 'echo -e "\ndefined( '\''WP_PROXY_HOST'\'' ) or define( '\''WP_PROXY_HOST'\'', '\''socks://host.docker.internal'\'' );\ndefined( '\''WP_PROXY_PORT'\'' ) or define( '\''WP_PROXY_PORT'\'', '\''8080'\'' );" | tee -a wp-config.php'
$ wp-env run cli cat wp-config.php | tail -n 2
ℹ Starting 'cat wp-config.php' on the cli container.
✔ Ran `cat wp-config.php` in 'cli'. (in 0s 645ms)
defined( 'WP_PROXY_HOST' ) or define( 'WP_PROXY_HOST', 'socks://host.docker.internal' );
defined( 'WP_PROXY_PORT' ) or define( 'WP_PROXY_PORT', '8080' );Now, try making a request to the Internet again:
$ wp-env run cli wp shell
ℹ Starting 'wp shell' on the cli container. Exit the WordPress shell with ctrl-c.
wp> wp_remote_retrieve_body( wp_remote_get( 'https://woocommerce.com/wp-json /helper/1.0/oauth/authorize' ) )
=> string(191963) "
<!DOCTYPE html>
...
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
[Status] Needs More InfoFollow-up required in order to be actionable.Follow-up required in order to be actionable.[Tool] Env/packages/env/packages/env
Type
Fields
Give feedbackNo fields configured for issues without a type.