1

I have been working locally on MAMP and now have deployed the site to Digital Ocean using this guide. However I can't access the site. for page links I get the service unavailable error, and for the admin I get the 'Craft can’t connect to the database with the credentials in craft/config/db.php.' error. i have checked my database credentials many times and they match.

return array(
    '*' => array(
        'tablePrefix' => 'craft'
    ),
    '000.00.000.00' => array(
        'server' => 'localhost',
        'user' => 'craftcms',
        'password' => '************',
        'database' => 'craft'
    ),
    'localhost' => array(
        'server' => 'localhost',
        'user' => 'root',
        'password' => '************',
        'database' => 'craftdev'
    ),
);

my general config settings are as follows:

return array(
    '*' => array(   
        //'siteUrl' => "//projectname:8888/html/",
        'environmentVariables' => array(
            'basePath' => '/users/toddpadwick/Sites/projectname/html/',
            'siteUrl'  => '//projectname:8888/html/',
        ),
        'testToEmailAddress' => '[email protected]',
        // Default Week Start Day (0 = Sunday, 1 = Monday...)
        'defaultWeekStartDay' => 0,
        // Enable CSRF Protection (recommended, will be enabled by default in Craft 3)
        'enableCsrfProtection' => true,
        // Whether "index.php" should be visible in URLs (true, false, "auto")
        'omitScriptNameInUrls' => 'auto',
        // Control Panel trigger word
        'cpTrigger' => 'admin',
        // Dev Mode (see https://craftcms.com/support/dev-mode)
        'devMode' => true,
    ),
    // Use IP address of your droplet below
    '000.00.000.00' => array(

        //'siteUrl' => 'http://000.00.000.00/',

        'environmentVariables' => array(
            'basePath' => '/var/www/html/',
            'siteUrl'  => 'http://000.00.000.00/',
        ),
        // Default Week Start Day (0 = Sunday, 1 = Monday...)
        'defaultWeekStartDay' => 0,
        // Enable CSRF Protection (recommended, will be enabled by default in Craft 3)
        'enableCsrfProtection' => true,
        // Whether "index.php" should be visible in URLs (true, false, "auto")
        'omitScriptNameInUrls' => 'auto',
        // Control Panel trigger word
        'cpTrigger' => 'admin',
        // Dev Mode (see https://craftcms.com/support/dev-mode)
        'devMode' => false,
    )
);

Any help would be greatly appreciated!

3 Answers 3

1

Could you post your nginx/apache configuration?

In short the configuration array key is matched based on the server name (server_name in nginx, ServerName in Apache httpd iirc).

If you're using some sort of default configuration it might not have a server_name, or a bogus one.

Thus, if your configuration array is like this:

<?php

return array(

  '1.2.3.4' => array(
    'someSetting' => 'foo'
  );
);

You should have a corresponding configuration in (nginx in this example):

server {
  listen 80;
  server_name 1.2.3.4;
  ....
}

If you have more than one host in server_name, Craft will match on the first.

3
  • Sorry, I am relatively new to this... Not sure how to access my nginx/apache config. I set up the server using Digital Oceans one click LAMP stack, and craft settings other than the db.config and general.config files are all as they are were out the box. Sep 21, 2017 at 11:01
  • I've never used their LAMP image, see if you have something in /etc/apache2/sites-enabled
    – Erik Weber
    Sep 21, 2017 at 11:12
  • By the way, I'd recommend looking into something like Serverpilot to do the LAMP installation and maintenance on the DO Droplet. It's also super simple to set up.
    – foamcow
    Sep 21, 2017 at 15:39
1

Are you able to use a domain name rather than an IP address?

If not, try moving the connection details into the '*' section like so;

return array(
    '*' => array(
        'tablePrefix' => 'craft'
        'server' => 'localhost',
        'user' => 'craftcms',
        'password' => '************',
        'database' => 'craft'
    ),

    'localhost' => array(
        'server' => 'localhost',
        'user' => 'root',
        'password' => '************',
        'database' => 'craftdev'
    ),
);

and give that a try

1

Turns out this was a stupid mistake: I just had a white-space before

Somehow it worked locally but not on the server.

Your Answer

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

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