Wp-cli: PHP Notice: Undefined index: HTTP_HOST

Created on 18 May 2017  路  3Comments  路  Source: wp-cli/wp-cli

Hi;

I'm learning WPCLI and everything works well on my LAMP in production but I have a misunderstood concept in my development environment which is
OS X with wordpress bitnami apps which come with :

wp --info
PHP binary: /Applications/wordpress-4.7.4-0/php/bin/php.bin
PHP version:    7.0.16
php.ini used:   /Applications/wordpress-4.7.4-0/php/etc/php.ini
WP-CLI root dir:    phar://wp-cli.phar
WP-CLI packages dir:    
WP-CLI global config:   
WP-CLI project config:  
WP-CLI version: 1.1.0

So I fixed the PATH in my .bash_profile and now I'm trying to fix this error
https://make.wordpress.org/cli/handbook/common-issues/#php-notice-undefined-index-on-_server-superglobal
I presume it's because I have those parameter in my wp-config.php

/**
 * The WP_SITEURL and WP_HOME options are configured to access from any hostname or IP address.
 * If you want to access only from an specific domain, you can modify them. For example:
 *  define('WP_HOME','http://example.com');
 *  define('WP_SITEURL','http://example.com');
 *
*/

define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/wordpress');
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] . '/wordpress');

But I just don't get the explaination and would like a concrete example such as
If my wordpress is accessible at http://host.local/wordpress

Regards ;)

Jonathan

unsupported

Most helpful comment

The param sent to defined() needs to be quoted, thus it should be:

if (defined('WP_CLI') && WP_CLI) {
     $_SERVER['HTTP_HOST'] = 'host.local';
}

All 3 comments

I presume it's because I have those parameter in my wp-config.php

This is correct. You'll need to set $_SERVER['HTTP_HOST'] in the CLI context. Something like this should work:

if ( defined( WP_CLI ) && WP_CLI ) {
    $_SERVER['HTTP_HOST'] = 'host.local';
}

As a heads up, GitHub issues are meant for enhancement requests and specific, reproducible bugs, not for general support questions. For support options, please review http://wp-cli.org/#support

The param sent to defined() needs to be quoted, thus it should be:

if (defined('WP_CLI') && WP_CLI) {
     $_SERVER['HTTP_HOST'] = 'host.local';
}

Or

if ( ! isset( $_SERVER['HTTP_HOST'] ) ) {
     $_SERVER['HTTP_HOST'] = 'localhost';
}

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fwaggle picture fwaggle  路  3Comments

schlessera picture schlessera  路  4Comments

dhalucario picture dhalucario  路  3Comments

ernilambar picture ernilambar  路  3Comments

vercotux picture vercotux  路  3Comments