<p>Include this if statement at the bottom of your <strong>config/db.php</strong> file</p>

<pre><code>// If a local config file exists, merge
if (is_array($localConfig = @include(CRAFT_CONFIG_PATH . 'local/db.php')))
{
    // does our default config already have a local key?
    if(array_key_exists('local', $config))
    {
        // If so, merge what's in our local/db.php
        $config['local'] = array_merge($config['local'], $localConfig);
    }
    else
    {
        // Otherwise, just set as our 'local' key
        $config['local'] = $localConfig;
    }
}

// return our $config back to craft
return $config;
</code></pre>

<p>Then create a <strong>config/local/db.php</strong> with your homestead configuration</p>

<pre><code>&lt;?php
/**
 * Local-only Database Configuration
 *
 * The returned array will be merged ONLY with the in-built 'local' array in config/db.php,
 *
 * Usage: duplicate file as `config/local/db.php` and cutomise values below.
 */

return array(
    'server'    =&gt; 'localhost',
    'user'      =&gt; 'homestead',
    'password'  =&gt; 'secret',
    'database'  =&gt; 'example'
);
</code></pre>

CC BY-SA 3.0
2017-05-15T13:29:48.527Z
2017-05-15T13:29:48.527Z
anandpatel
<p>Is it possible to have multiple local database configurations? I have just setup homestead but I work in a team who use MAMP, and MAMP username password is <strong>root</strong> whereas homestead uses <strong>homestead</strong> and <strong>secret</strong>.</p>

<p>So if I change the details it works fine for homestead but then breaks for MAMP users.</p>

<pre><code>'local' =&gt; array(
    'server' =&gt; 'localhost',
    'database' =&gt; 'craft',
    'user' =&gt; 'root',
    'password' =&gt; 'root'
)

'local' =&gt; array(
    'server' =&gt; 'localhost',
    'database' =&gt; 'craft',
    'user' =&gt; 'homestead',
    'password' =&gt; 'secret'
)
</code></pre>

<p>Is there a way to have local set both to be compatible with homestead and MAMP at the same time?</p>

CC BY-SA 3.0
2017-05-12T15:27:18.423Z
If you define your environment variables following this guide, it is easy to maintain this using the same repository: https://nystudio107.com/blog/multi-environment-config-for-craft-cms
Max Strebel
CC BY-SA 3.0
2017-05-12T15:36:12.203Z
Could you add this as an answer, Lazy Pirate? Add a bit more information (rather than just the link), and you've got my vote.
Stephen Lewis
<database><config><mamp>
Homestead DB config
# Homestead DB config

(Asked by: username_0 on 2017-05-12)

Is it possible to have multiple local database configurations? I have just setup homestead but I work in a team who use MAMP, and MAMP username password is root whereas homestead uses homestead and secret.
So if I change the details it works fine for homestead but then breaks for MAMP users.
'local' => array(
    'server' => 'localhost',
    'database' => 'craft',
    'user' => 'root',
    'password' => 'root'
)

'local' => array(
    'server' => 'localhost',
    'database' => 'craft',
    'user' => 'homestead',
    'password' => 'secret'
)

Is there a way to have local set both to be compatible with homestead and MAMP at the same time?

**Tags:** database, config, mamp
> **Comments:**
> **username_1**: If you define your environment variables following this guide, it is easy to maintain this using the same repository: https://nystudio107.com/blog/multi-environment-config-for-craft-cms  
> **username_2**: Could you add this as an answer, Lazy Pirate? Add a bit more information (rather than just the link), and you've got my vote.  

---

## 1 answers

### Answer by username_0 on 2017-05-15. Score: 2 | Accepted answer

Include this if statement at the bottom of your config/db.php file
// If a local config file exists, merge
if (is_array($localConfig = @include(CRAFT_CONFIG_PATH . 'local/db.php')))
{
    // does our default config already have a local key?
    if(array_key_exists('local', $config))
    {
        // If so, merge what's in our local/db.php
        $config['local'] = array_merge($config['local'], $localConfig);
    }
    else
    {
        // Otherwise, just set as our 'local' key
        $config['local'] = $localConfig;
    }
}

// return our $config back to craft
return $config;

Then create a config/local/db.php with your homestead configuration
 'localhost',
    'user'      => 'homestead',
    'password'  => 'secret',
    'database'  => 'example'
);


---

