<p>It looks like <code>getenv</code> returns a string (or <code>false</code> 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, <code>(bool)'false'</code> gives <code>true</code>, not <code>false</code>. There are two possible solutions:</p>

<ol>
<li><p>Set the variable to <code>0</code> instead of <code>false</code> in your <code>.env</code> file:</p>

<pre><code>DEV_MODE=0
AUTO_UPDATE=0
</code></pre>

<p>And then in your config:</p>

<pre><code>'devMode' =&gt; (bool)getenv('DEV_MODE')
</code></pre>

<p>This works because <code>(bool)'0'</code> gives <code>false</code>.</p></li>
<li><p>Use <a href="https://stackoverflow.com/questions/4775294/parsing-a-string-into-a-boolean-value-in-php/10645030#10645030">this solution</a>:</p>

<pre><code>'devMode' =&gt; filter_var(getenv('DEV_MODE'), FILTER_VALIDATE_BOOLEAN);
</code></pre>

<p>This works because the <code>FILTER_VALIDATE_BOOLEAN</code> filter returns <code>TRUE</code> for <code>"1"</code>, <code>"true"</code>, <code>"on"</code> and <code>"yes"</code>, and returns <code>FALSE</code> for any other value.</p></li>
</ol>

CC BY-SA 4.0
2016-02-05T14:00:35.403Z
2019-01-10T20:21:27.440Z
2019-01-10T20:21:27.440Z
carlcs
<p>I'm using dotphpenv for environment specific config. </p>

<p>This works perfectly for my db config. I added another 2 environment vars for <code>devMode</code> and <code>allowAutoUpdates</code></p>

<pre><code>DEV_MODE=false
AUTO_UPDATE=false
</code></pre>

<p>and updated <code>general.php</code> </p>

<pre><code>&lt;?php

return array(

  // Default

  '*' =&gt; array(
    ...
    'devMode' =&gt; getenv('DEV_MODE'),
    'allowAutoUpdates' =&gt; getenv('AUTO_UPDATE'),
    ...
  )
);
</code></pre>

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

<p>If I set both to <code>false</code> 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.</p>

CC BY-SA 3.0
2016-02-05T12:04:24.423Z
Did you try to echo it from the general.php? `echo getenv('DEV_MODE');`
carlcs
CC BY-SA 3.0
2016-02-05T12:16:07.600Z
I tried `var_dump(getenv('DEV_MODE'));
exit;` inside index.php and it outputs as false there but yeah, ignored by system
Steven Grant
<config><multi-environment><environments><configuration><environmentvariables>
devMode, phpdotenv variable ignored
# devMode, phpdotenv variable ignored

(Asked by: username_0 on 2016-02-05)

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
DEV_MODE=false
AUTO_UPDATE=false

and updated general.php 
 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.

**Tags:** config, multi-environment, environments, configuration, environmentvariables

> **Comments:**
> **username_1**: Did you try to echo it from the general.php? `echo getenv('DEV_MODE');`  
> **username_0**: I tried `var_dump(getenv('DEV_MODE')); exit;` inside index.php and it outputs as false there but yeah, ignored by system  

---

## 1 answers

### Answer by username_1 on 2016-02-05. Score: 6 | Accepted answer

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:

Set the variable to 0 instead of false in your .env file:
DEV_MODE=0
AUTO_UPDATE=0

And then in your config:
'devMode' => (bool)getenv('DEV_MODE')

This works because (bool)'0' gives false.
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.


---

