1

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

<?php

return array(
    '*' => 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

<?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 <strong><code>$craftPath</code></strong> is set correctly in '.__FILE__);
}

require_once $path;

Help needed and much appreciated!

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/'
        )
    )
);
  • Turns out it was a permissions issue! – JackO Feb 5 '16 at 19:44
  • 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 Nov 1 '16 at 11:30
  • As obvious as that may seem - I've never tried it but it sure seems like it would work. :) – Damon Nov 1 '16 at 19:18
1

You might find this helpful: Multi-Environment Config for Craft CMS

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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