I'm using dotphpenv for environment specific config.

This works perfectly for my db config. I added another 2 environment vars for devMode and allowAutoUpdates


and updated general.php


return array(

  // Default

  '*' => array(
    'devMode' => getenv('DEV_MODE'),
    'allowAutoUpdates' => getenv('AUTO_UPDATE'),

But with that set, dev mode and auto-update are still available to production.

If I set both to false we have no problem. This is obviously a phpdotenv thing because Craft is doing what it's supposed to but if anyone can shed light I'd appreciate it.

  • Did you try to echo it from the general.php? echo getenv('DEV_MODE');
    – carlcs
    Feb 5 '16 at 12:04
  • I tried var_dump(getenv('DEV_MODE')); exit; inside index.php and it outputs as false there but yeah, ignored by system Feb 5 '16 at 12:16

It looks like getenv returns a string (or false if the variable is not set, but it is in this case). So you need to cast the string to a boolean value to make it work. However, (bool)'false' gives true, not false. There are two possible solutions:

  1. Set the variable to 0 instead of false in your .env file:


    And then in your config:

    'devMode' => (bool)getenv('DEV_MODE')

    This works because (bool)'0' gives false.

  2. Use this solution:

    'devMode' => filter_var(getenv('DEV_MODE'), FILTER_VALIDATE_BOOLEAN);

    This works because the FILTER_VALIDATE_BOOLEAN filter returns TRUE for "1", "true", "on" and "yes", and returns FALSE for any other value.

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.