<p>You might find this helpful: <a href="https://nystudio107.com/blog/multi-environment-config-for-craft-cms" rel="nofollow noreferrer">Multi-Environment Config for Craft CMS</a></p>

CC BY-SA 3.0
2016-12-04T17:23:56.680Z
2016-12-04T17:23:56.680Z
andrew.welch
<p>Here is what my configuration looks like. Ideally, I'd like to swap out the hard-coded <code>baseUrl</code> with something like I have for <code>basePath</code>. That way the other members on my team can call/put the site wherever they want and it won't break anything.</p>

<p>I don't make any changes to <code>index.php</code>.</p>

<p>Hope this helps!</p>

<p><strong>db.php</strong></p>

<pre><code>return array(
'*' =&gt; array(
    'tablePrefix' =&gt; ''
),
'.dev' =&gt; array(
    'server' =&gt; 'localhost',
    'user' =&gt; 'username',
    'password' =&gt; 'password',
    'database' =&gt; 'dbname'
),
'mysite.stagingdomain.com' =&gt; array(
    'server' =&gt; '12.345.67.890',
    'user' =&gt; 'username',
    'password' =&gt; 'password',
    'database' =&gt; 'dbname'
),
'mysite.com' =&gt; array(
    'server' =&gt; '12.345.67.890',
    'user' =&gt; 'username',
    'password' =&gt; 'password',
    'database' =&gt; 'dbname'
)
</code></pre>

<p>);</p>

<p><strong>general.php</strong></p>

<pre><code>return array(
    '*' =&gt; array(
    'cpTrigger' =&gt; 'admin',  // whatever you want
    'omitScriptNameInUrls' =&gt; true,
    'enableCsrfProtection' =&gt; true
),
'.dev' =&gt; array(
    'devMode' =&gt; true,
    'siteUrl' =&gt; 'http://mysite.dev/',
    'environmentVariables' =&gt; array(
        'basePath' =&gt; $_SERVER['DOCUMENT_ROOT'] . '/',
        'baseUrl' =&gt; 'http://mysite.dev/', 
    )
),
'mysite.stagingdomain.com' =&gt; array(
    'devMode' =&gt; true,
    'siteUrl' =&gt; 'http://mysite.stagingdomain.com/',
    'environmentVariables' =&gt; array(
        'basePath' =&gt; $_SERVER['DOCUMENT_ROOT'] . '/',
        'baseUrl' =&gt; 'http://mysite.stagingdomain.com/'
    )
),
'mysite.com' =&gt; array(
    'siteUrl' =&gt; 'http://www.mysite.com/',
    'environmentVariables' =&gt; array(
        'basePath' =&gt; $_SERVER['DOCUMENT_ROOT'] . '/',
        'baseUrl' =&gt; 'http://www.mysite.com/'
        )
    )
);
</code></pre>

CC BY-SA 3.0
2016-02-05T19:44:41.957Z
Turns out it was a permissions issue!
JackO
CC BY-SA 3.0
2016-11-01T11:30:57.190Z
I would think, as long as your site root is at web root (not in a subfolder), you could set `'baseUrl' => '/'` to avoid hard coding the whole URL, yes?
Philip Jones
CC BY-SA 3.0
2016-11-01T19:18:26.473Z
As obvious as that may seem - I've never tried it but it sure seems like it would work. :)
Damon
CC BY-SA 3.0
2016-02-05T16:04:42.997Z
2016-02-05T17:00:45.563Z
2016-02-05T17:00:45.563Z
Damon
<p>Being driven to distraction trying to setup multiple environments with Craft. I have Craft running (and working) locally without issue. I have created a staging server with Digital Ocean and setup the appropriate database. I'm using DeployBot to push changes from Github.</p>

<p>However upon trying to access the remote server, I get the following errors:</p>

<blockquote>
  <p>Service Unavailable</p>
  
  <p>Our site is temporarily unavailable. Please try again later.</p>
</blockquote>

<p>and </p>

<blockquote>
  <p>Craft can’t connect to the database with the credentials in
  craft/config/db.php.</p>
</blockquote>

<p>I'm sure there is an obvious solution to why this isn't working, but I'm yet to find it.</p>

<p>Here are my db.php and general.php files with sensitive data redacted:</p>

<p><strong>db.php</strong>
    

<pre><code>return array(
  '*' =&gt; array(
    'database' =&gt; '******',
    'tablePrefix' =&gt; 'craft',
  ),

  'localhost' =&gt; array(
    'server' =&gt; 'localhost',
    'user' =&gt; 'root',
    'password' =&gt; 'root',
  ),

  // Use IP of your droplet and MySQL credentials of a user you created
  '000.000.000.000' =&gt; array(
    'server' =&gt; '000.000.000.000',
    'user' =&gt; 'root',
    'password' =&gt; '***********',
  )
);
</code></pre>

<p><strong>config.php</strong></p>

<pre><code>&lt;?php

return array(
    '*' =&gt; array(
        'omitScriptNameInUrls' =&gt; true,
        'devMode' =&gt; true,
        'loginPath' =&gt; 'users/login',
        'postLoginRedirect' =&gt; 'commerce/customer',
        'setPasswordPath' =&gt; 'users/setpassword',
        'enableCsrfProtection' =&gt; true,
    ),

    '000.000.000.000' =&gt; array(
      'siteUrl' =&gt; 'http://000.000.000.000/',
      'environmentVariables' =&gt; array(
        'basePath' =&gt; '/var/www/html/',
        'baseUrl' =&gt; 'http://000.000.000.000/',
      )
    ),

);
</code></pre>

<p><strong>Also index.php file for good measure</strong></p>

<pre><code>&lt;?php

// Path to your craft/ folder
$craftPath = '../craft';

// Do not edit below this line
$path = rtrim($craftPath, '/').'/app/index.php';

if (!is_file($path))
{
    if (function_exists('http_response_code'))
    {
        http_response_code(503);
    }

    exit('Could not find your craft/ folder. Please ensure that &lt;strong&gt;&lt;code&gt;$craftPath&lt;/code&gt;&lt;/strong&gt; is set correctly in '.__FILE__);
}

require_once $path;
</code></pre>

<p>Help needed and much appreciated!</p>

<database><server><multi-environment>
Multi-Environment Config Database Credentials
# Multi-Environment Config Database Credentials

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

Being driven to distraction trying to setup multiple environments with Craft. I have Craft running (and working) locally without issue. I have created a staging server with Digital Ocean and setup the appropriate database. I'm using DeployBot to push changes from Github.
However upon trying to access the remote server, I get the following errors:

Service Unavailable
Our site is temporarily unavailable. Please try again later.

and 

Craft can’t connect to the database with the credentials in
  craft/config/db.php.

I'm sure there is an obvious solution to why this isn't working, but I'm yet to find it.
Here are my db.php and general.php files with sensitive data redacted:
db.php
return array(
  '*' => array(
    'database' => '******',
    'tablePrefix' => 'craft',
  ),

  'localhost' => array(
    'server' => 'localhost',
    'user' => 'root',
    'password' => 'root',
  ),

  // Use IP of your droplet and MySQL credentials of a user you created
  '000.000.000.000' => array(
    'server' => '000.000.000.000',
    'user' => 'root',
    'password' => '***********',
  )
);

config.php
 array(
        'omitScriptNameInUrls' => true,
        'devMode' => true,
        'loginPath' => 'users/login',
        'postLoginRedirect' => 'commerce/customer',
        'setPasswordPath' => 'users/setpassword',
        'enableCsrfProtection' => true,
    ),

    '000.000.000.000' => array(
      'siteUrl' => 'http://000.000.000.000/',
      'environmentVariables' => array(
        'basePath' => '/var/www/html/',
        'baseUrl' => 'http://000.000.000.000/',
      )
    ),

);

Also index.php file for good measure
$craftPath is set correctly in '.__FILE__);
}

require_once $path;

Help needed and much appreciated!

**Tags:** database, server, multi-environment


---

## 2 answers

### Answer by username_1 on 2016-12-04. Score: 1

You might find this helpful: [Multi-Environment Config for Craft CMS](https://nystudio107.com/blog/multi-environment-config-for-craft-cms)


---

### Answer by username_2 on 2016-02-05. Score: 1

Here is what my configuration looks like. Ideally, I'd like to swap out the hard-coded baseUrl with something like I have for basePath. That way the other members on my team can call/put the site wherever they want and it won't break anything.
I don't make any changes to index.php.
Hope this helps!
db.php
return array(
'*' => array(
    'tablePrefix' => ''
),
'.dev' => array(
    'server' => 'localhost',
    'user' => 'username',
    'password' => 'password',
    'database' => 'dbname'
),
'mysite.stagingdomain.com' => array(
    'server' => '12.345.67.890',
    'user' => 'username',
    'password' => 'password',
    'database' => 'dbname'
),
'mysite.com' => array(
    'server' => '12.345.67.890',
    'user' => 'username',
    'password' => 'password',
    'database' => 'dbname'
)

);
general.php
return array(
    '*' => array(
    'cpTrigger' => 'admin',  // whatever you want
    'omitScriptNameInUrls' => true,
    'enableCsrfProtection' => true
),
'.dev' => array(
    'devMode' => true,
    'siteUrl' => 'http://mysite.dev/',
    'environmentVariables' => array(
        'basePath' => $_SERVER['DOCUMENT_ROOT'] . '/',
        'baseUrl' => 'http://mysite.dev/', 
    )
),
'mysite.stagingdomain.com' => array(
    'devMode' => true,
    'siteUrl' => 'http://mysite.stagingdomain.com/',
    'environmentVariables' => array(
        'basePath' => $_SERVER['DOCUMENT_ROOT'] . '/',
        'baseUrl' => 'http://mysite.stagingdomain.com/'
    )
),
'mysite.com' => array(
    'siteUrl' => 'http://www.mysite.com/',
    'environmentVariables' => array(
        'basePath' => $_SERVER['DOCUMENT_ROOT'] . '/',
        'baseUrl' => 'http://www.mysite.com/'
        )
    )
);

> **Comments:**
> **username_0**: Turns out it was a permissions issue!  
> **username_3**: I would think, as long as your site root is at web root (not in a subfolder), you could set `'baseUrl' => '/'` to avoid hard coding the whole URL, yes?  
> **username_2**: As obvious as that may seem - I've never tried it but it sure seems like it would work. :)  

---

