Notice: Undefined index: REQUEST_SCHEME in thrown in WP-CLI


  • | 2530 points

    After installing WordPress via Quick app, in config file it adds two lines:

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

    Because of that, In WP CLI we receive notice while executing commands:

    $ wp plugin activate woocommerce
    
    Notice: Undefined index: REQUEST_SCHEME in phar://C:/laragon/usr/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1150) : eval()'d code on line 29
    
    Call Stack:
        0.2760     393544   1. {main}() C:\laragon\usr\bin\wp:0
        0.4327     879272   2. include('phar://C:/laragon/usr/bin/wp/php/boot-phar.php') C:\laragon\usr\bin\wp:4
        0.4462     886408   3. include('phar://C:/laragon/usr/bin/wp/vendor/wp-cli/wp-cli/php/wp-cli.php') phar://C:/laragon/usr/bin/wp/php/boot-phar.php:11
        0.4556     897896   4. WP_CLI\bootstrap() phar://C:/laragon/usr/bin/wp/vendor/wp-cli/wp-cli/php/wp-cli.php:23
        1.2518    8162048   5. WP_CLI\Bootstrap\LaunchRunner->process() phar://C:/laragon/usr/bin/wp/vendor/wp-cli/wp-cli/php/bootstrap.php:74
        1.2519    8162088   6. WP_CLI\Runner->start() phar://C:/laragon/usr/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Bootstrap/LaunchRunner.php:23
        1.2646    8162992   7. WP_CLI\Runner->load_wordpress() phar://C:/laragon/usr/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php:1111
        1.3066    8180096   8. eval('/**
    ...
    ...
    ...
    ') phar://C:/laragon/usr/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php:1150
    
    Plugin 'woocommerce' activated.
    Success: Activated 1 of 1 plugins.
    

  • | 2530 points

    This was the code added after define to MySQL DB Password:

    /** MySQL database password */
    define('DB_PASSWORD', '');
    define('WP_SITEURL', $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST']);
    define('WP_HOME',    $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST']);
    

    Now removing above laragon define for site URL and moving them after DB_COLLATE with check for WP_CLI resolves my problem :)

    /** The Database Collate type. Don't change this if in doubt. */
    define('DB_COLLATE', '');
    
    /** Sets up WordPress URL. */
    if ( ! defined( 'WP_CLI' ) ) {
    	define( 'WP_SITEURL', $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] );
    	define( 'WP_HOME',    $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] );
    }
    

    What I have done here is that, I have checked if WP_CLI has not been defined or not. Another cool stuff I suggest is please add those lines after DB_COLLATE and not after DB_PASSWORD because till DB_COLLATE those configs are for Database and placing Advanced URL options configurations in the middle of Database configs in not highly appreciated :)


  • administrators
    | 105080 points

    @shivapoudel : You must be a WordPress guru!
    You are right. I will fix it in the next version of Laragon. Thanks!


  • | 2530 points

    Is there any possibilities I could contribute this kind of changes in laragon in GitHub or somewhere else?


  • | 2530 points

    When will this be shipped :)


  • administrators
    | 105080 points

    @shivapoudel : I fixed it and will release Laragon soon.


  • administrators
    | 105080 points

    @shivapoudel : I've released Laragon 4.0.4 which fixed the issue.
    Many thanks for your information!


  • | 2530 points

    @leokhoa You can mark solved for this thread :)


  • | 336 points

    I created WordPress installation using QuickApp. Also, I'm using Apache with SSL enabled.

    The problem is that both "WordPress Address (URL)" and "Site Address (URL)" are greyed out after installation so I had to manually remove following code from wp-config.php:

    if ( ! defined( 'WP_CLI' ) ) {
    	define( 'WP_SITEURL', $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] );
    	define( 'WP_HOME',    $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] );
    }
    

    Both fields became editable so I was able to switch the site to https. But the problem is that front end doesn't redirect to https anymore like my older sites.
    Is there a simple way to fix this for future installations?


Log in to reply
 

Looks like your connection to Laragon was lost, please wait while we try to reconnect.