I am confronted to the error PHP Notice: Undefined index: HTTP_HOST
when trying to use wp-cli on my wordpress install because I have this line in my wp-config.php:
define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/');
Bug is reported here https://github.com/wp-cli/wp-cli/issues/730 and there is a solution here https://make.wordpress.org/cli/handbook/common-issues/#php-notice-undefined-index-on-_server-superglobal which is to set a default value in wp-cli context:
if ( defined( 'WP_CLI' ) && WP_CLI && ! isset( $_SERVER['HTTP_HOST'] ) ) {
$_SERVER['HTTP_HOST'] = 'example.com';
}
I don't understand this solution though. Isn't the point of $_SERVER['HTTP_HOST']
NOT to have to set a value for the current domain name? Or does this example mean that I can put ANY value for $_SERVER['HTTP_HOST']
, no matter my real domain name, as it won't be used by wp-cli?