<p>For anyone interested, I had set web/index.php to production.</p>

<p>The reason why both staging and production were working was due to me using the same username and password for the database.</p>

<p>Once I had changed this to dev, it now works so I no longer need the .env file.</p>

CC BY-SA 3.0
2018-03-26T11:30:15.603Z
2018-03-26T11:30:15.603Z
Dan
<p>I am at the very early stages of using CractCMS but I'm keen to get off to the correct start, writing notes as I go along etc but I cannot figure this issue out.</p>

<p>I have setup the Multi-Environment Configs to allow me to use, dev, staging and production sites, staging and production appear to work correctly but development site is causing issues.</p>

<p>I know it's something to do with the .env file and</p>

<pre><code>ENVIRONMENT="production"
</code></pre>

<p>If I change that to</p>

<pre><code>ENVIRONMENT="dev"
</code></pre>

<p>The development site will work.</p>

<p>What I can't understand is, both staging and production work so why not development?</p>

<p>I thought by using db.php and general.php I could do away with .env? Other than this line I can.</p>

<p>Here's my General.php code</p>

<pre><code>&lt;?php

return [
// Global settings
'*' =&gt; [
    // Default Week Start Day (0 = Sunday, 1 = Monday...)
    'defaultWeekStartDay' =&gt; 1,

    // Enable CSRF Protection (recommended)
    'enableCsrfProtection' =&gt; true,

    // Whether "index.php" should be visible in URLs
    'omitScriptNameInUrls' =&gt; true,

    // Control Panel trigger word
    'cpTrigger' =&gt; 'admin',


    // The secure key Craft will use for hashing and encrypting data
    'securityKey' =&gt; '*******************************',
],

// Dev environment settings
'dev' =&gt; [

    // Base site URL
    'siteUrl' =&gt; null,



    'basePath' =&gt; '@webroot/cpresources',

    'baseUrl'  =&gt; 'https://mydomain.test',
],

// Staging environment settings
'staging' =&gt; [
    // Base site URL
    'siteUrl' =&gt; null,

    'basePath' =&gt; '@webroot/cpresources',

    'baseUrl'  =&gt; 'https://staging.mydomain.co.uk',
],

// Production environment settings
'production' =&gt; [
    // Base site URL
    'siteUrl' =&gt; null,

    'basePath' =&gt; '@webroot/cpresources',

    'baseUrl'  =&gt; 'https://mydomain.co.uk',
],
];
</code></pre>

<p>Here's my db.php code</p>

<pre><code>&lt;?php

return array(
'*' =&gt; array(
    'tablePrefix' =&gt; '',
    'driver' =&gt; 'mysql',
    'schema' =&gt; 'public',
),
'dev' =&gt; [
    // Base site URL
    'server' =&gt; 'localhost',
    'user' =&gt; 'myusername',
    'password' =&gt; '*************',
    'database' =&gt; 'mydatabasename',
],
'staging' =&gt; array(
    'server' =&gt; 'localhost',
    'user' =&gt; 'myusername',
    'password' =&gt; '*************',
    'database' =&gt; 'craft_cms_staging',
),
'production' =&gt; array(
    'server' =&gt; 'localhost',
    'user' =&gt; 'myusername',
    'password' =&gt; '*',
    'database' =&gt; 'craft_cms_production',
),
);
</code></pre>

<p>Now before anyone says anything about uploading db.php and general.php to git etc because of passwords, I have put both these files in the .gitignore file. I felt this was the best option but if I'm wrong, please explain?</p>

<craft3><multi-environment>
Multi-Environment Configs in CraftCMS 3
# Multi-Environment Configs in CraftCMS 3

(Asked by: username_0 on 2018-03-26)

I am at the very early stages of using CractCMS but I'm keen to get off to the correct start, writing notes as I go along etc but I cannot figure this issue out.
I have setup the Multi-Environment Configs to allow me to use, dev, staging and production sites, staging and production appear to work correctly but development site is causing issues.
I know it's something to do with the .env file and
ENVIRONMENT="production"

If I change that to
ENVIRONMENT="dev"

The development site will work.
What I can't understand is, both staging and production work so why not development?
I thought by using db.php and general.php I could do away with .env? Other than this line I can.
Here's my General.php code
 [
    // Default Week Start Day (0 = Sunday, 1 = Monday...)
    'defaultWeekStartDay' => 1,

    // Enable CSRF Protection (recommended)
    'enableCsrfProtection' => true,

    // Whether "index.php" should be visible in URLs
    'omitScriptNameInUrls' => true,

    // Control Panel trigger word
    'cpTrigger' => 'admin',


    // The secure key Craft will use for hashing and encrypting data
    'securityKey' => '*******************************',
],

// Dev environment settings
'dev' => [

    // Base site URL
    'siteUrl' => null,



    'basePath' => '@webroot/cpresources',

    'baseUrl'  => 'https://mydomain.test',
],

// Staging environment settings
'staging' => [
    // Base site URL
    'siteUrl' => null,

    'basePath' => '@webroot/cpresources',

    'baseUrl'  => 'https://staging.mydomain.co.uk',
],

// Production environment settings
'production' => [
    // Base site URL
    'siteUrl' => null,

    'basePath' => '@webroot/cpresources',

    'baseUrl'  => 'https://mydomain.co.uk',
],
];

Here's my db.php code
 array(
    'tablePrefix' => '',
    'driver' => 'mysql',
    'schema' => 'public',
),
'dev' => [
    // Base site URL
    'server' => 'localhost',
    'user' => 'myusername',
    'password' => '*************',
    'database' => 'mydatabasename',
],
'staging' => array(
    'server' => 'localhost',
    'user' => 'myusername',
    'password' => '*************',
    'database' => 'craft_cms_staging',
),
'production' => array(
    'server' => 'localhost',
    'user' => 'myusername',
    'password' => '*',
    'database' => 'craft_cms_production',
),
);

Now before anyone says anything about uploading db.php and general.php to git etc because of passwords, I have put both these files in the .gitignore file. I felt this was the best option but if I'm wrong, please explain?

**Tags:** craft3, multi-environment

---

## 1 answers

### Answer by username_0 on 2018-03-26. Score: 1

For anyone interested, I had set web/index.php to production.

The reason why both staging and production were working was due to me using the same username and password for the database.

Once I had changed this to dev, it now works so I no longer need the .env file.


---

