studio24 / wordpress-multi-env-config

WordPress multi-environment config

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot determine current environment domain

alexanderkladov opened this issue · comments

Hi,

I keep getting the following error in my LIVE environments for some reason:

[23-Apr-2018 11:15:54 Australia/Brisbane] PHP Fatal error:  Uncaught Exception: Cannot determine current environment domain, make sure this is set in wp-config.env.php in /home/app/public_html/config/wp-config.load.php:100
Stack trace:
#0 /home/app/public_html/config/wp-config.load.php(124): load_environment_config()
#1 /home/app/public_html/wp-config.php(18): require_once('/home/app...')
#2 /home/app/public_html/wp-load.php(37): require_once('/home/app...')
#3 /home/app/public_html/wp-blog-header.php(13): require_once('/home/app...')
#4 /home/app/public_html/index.php(17): require('/home/app..')
#5 {main}
  thrown in /home/app/public_html/config/wp-config.load.php on line 100

IF my wp-config.env.php is configured like so:

$env = [
  'test' => [
    'domain' => 'domain_local.test',
    'path'   => '',
    'ssl'    => false,
  ],
  'staging' => [
    'domain'  => 'staging.domain_staging.com.au',
    'path'    => 'domain_live',
    'ssl'     => true,
  ],
  'live' => [
    'domain' => 'www.domain_live.com.au',
    'path'   => '',
    'ssl'    => true,
  ],
];

The only way to stop the error from happening is to modify LIVE environment to include a non-www version like this:

$env = [
  'test' => [
    'domain' => 'domain_local.test',
    'path'   => '',
    'ssl'    => false,
  ],
  'staging' => [
    'domain'  => 'staging.domain_staging.com.au',
    'path'    => 'domain_live',
    'ssl'     => true,
  ],
  'live' => [
    'domain' => ['www.domain_live.com.au', 'domain_live.com.au'],
    'path'   => '',
    'ssl'    => true,
  ],
];

Has anyone else come across this problem and found a solution?

Cheers,
Alex

Alex, this is likely due to your webserver setup. For example, Apache uses the ServerName property to set the website hostname. My guess is your setup is:

ServerName domain_live.com.au ServerAlias www.domain_live.com.au

In the above example, you should set the 'domain' to: domain_live.com.au

FYI best practise is to redirect one of these to the other and only use one server name for your site. What I'd normally do is setup

ServerName www.domain_live.com.au

As the primary domain and then have a redirect on the other variant to the www. site. E.g.

ServerName domain_live.com.au Redirect / https://www.domain_live.com.au/

Then you can use the www domain in the config file.