Morning folks. First time doing multi-environment in Craft 3, and separate installations for staging and production is a bit overkill for this particular project. Instead I just want to show a few new bits in templates on the staging subdomain until sign-off.

Staging domain (https://staging.adddress.com) is pointed at the production 'public' directory. So in Craft 2, I'd just let the 'staging' key in my config.php set all the necessary environment variables. But in Craft 3 don't I need to load the correct .env first? Since it's all the same installation, is there a way to switch to .env.staging when on the staging subdomain? Is that the correct/best approach? Thanks.


Alright, so turns out all I need to do is comment out the following line in index.php:

define('CRAFT_ENVIRONMENT', getenv('ENVIRONMENT') ?: 'production');

Now I can use config.php keys, same way I did in Craft 2. For example:

'*' => [
    // My default/production variables
    'devMode' => false,
// Local
'address.test' => [
    // Local variables
    'devMode' => true,
// Staging
'staging.address.com' => [
    // Staging variables
    'devMode' => true,

Thanks to Luke James for the assist on Slack.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.