2

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?

2

1 Answer 1

2

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

<?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'    => 'localhost',
    'user'      => 'homestead',
    'password'  => 'secret',
    'database'  => 'example'
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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