Answers.Body: <p>Are you able to use a domain name rather than an IP address?</p>
  
  <p>If not, try moving the connection details into the '*' section like so;</p>
  
  <pre><code>return array(
      '*' =&gt; array(
          'tablePrefix' =&gt; 'craft'
          'server' =&gt; 'localhost',
          'user' =&gt; 'craftcms',
          'password' =&gt; '************',
          'database' =&gt; 'craft'
      ),
  
      'localhost' =&gt; array(
          'server' =&gt; 'localhost',
          'user' =&gt; 'root',
          'password' =&gt; '************',
          'database' =&gt; 'craftdev'
      ),
  );
  </code></pre>
  
  <p>and give that a try</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-21T13:18:30.227Z
Answers.LastActivityDate: 2017-09-21T13:18:30.227Z
Answers.UserDisplayName: foamcow
Answers.Body: <p>Turns out this was a stupid mistake: I just had a white-space before 
  
  <p>Somehow it worked locally but not on the server. </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-26T10:02:02.180Z
Answers.LastActivityDate: 2017-09-26T10:02:02.180Z
Answers.UserDisplayName: ToddPadwick
Answers.Body: <p>Could you post your nginx/apache configuration?</p>
  
  <p>In short the configuration array key is matched based on the server name (server_name in nginx, ServerName in Apache httpd iirc).</p>
  
  <p>If you're using some sort of default configuration it might not have a server_name, or a bogus one.</p>
  
  <p>Thus, if your configuration array is like this:</p>
  
  <pre><code>&lt;?php
  
  return array(
  
    '1.2.3.4' =&gt; array(
      'someSetting' =&gt; 'foo'
    );
  );
  </code></pre>
  
  <p>You should have a corresponding configuration in (nginx in this example):</p>
  
  <pre><code>server {
    listen 80;
    server_name 1.2.3.4;
    ....
  }
  </code></pre>
  
  <p>If you have more than one host in server_name, Craft will match on the first.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-21T11:01:32.137Z
Answers.Text: 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.
Answers.UserDisplayName: ToddPadwick
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-21T11:12:44.313Z
Answers.Text: I've never used their LAMP image, see if you have something in /etc/apache2/sites-enabled
Answers.UserDisplayName: Erik Weber
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-21T15:39:37.680Z
Answers.Text: 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.
Answers.UserDisplayName: foamcow
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-21T10:40:47.590Z
Answers.LastActivityDate: 2017-09-21T10:40:47.590Z
Answers.UserDisplayName: Erik Weber
Body: <p>I have been working locally on MAMP and now have deployed the site to Digital Ocean using this <a href="https://deploybot.com/guides/deploy-craft-cms-to-digitalocean" rel="nofollow noreferrer">guide</a>.
  However I can't access the site. for page links I get the service unavailable error, and for the admin I get the <code>'Craft can’t connect to the database with the credentials in craft/config/db.php.'</code> error. 
  i have checked my database credentials many times and they match. </p>
  
  <p>
  
  <pre><code>return array(
      '*' =&gt; array(
          'tablePrefix' =&gt; 'craft'
      ),
      '000.00.000.00' =&gt; array(
          'server' =&gt; 'localhost',
          'user' =&gt; 'craftcms',
          'password' =&gt; '************',
          'database' =&gt; 'craft'
      ),
      'localhost' =&gt; array(
          'server' =&gt; 'localhost',
          'user' =&gt; 'root',
          'password' =&gt; '************',
          'database' =&gt; 'craftdev'
      ),
  );
  </code></pre>
  
  <p>my general config settings are as follows:</p>
  
  <pre><code>return array(
      '*' =&gt; array(   
          //'siteUrl' =&gt; "//projectname:8888/html/",
          'environmentVariables' =&gt; array(
              'basePath' =&gt; '/users/toddpadwick/Sites/projectname/html/',
              'siteUrl'  =&gt; '//projectname:8888/html/',
          ),
          'testToEmailAddress' =&gt; 'email@email.com',
          // Default Week Start Day (0 = Sunday, 1 = Monday...)
          'defaultWeekStartDay' =&gt; 0,
          // Enable CSRF Protection (recommended, will be enabled by default in Craft 3)
          'enableCsrfProtection' =&gt; true,
          // Whether "index.php" should be visible in URLs (true, false, "auto")
          'omitScriptNameInUrls' =&gt; 'auto',
          // Control Panel trigger word
          'cpTrigger' =&gt; 'admin',
          // Dev Mode (see https://craftcms.com/support/dev-mode)
          'devMode' =&gt; true,
      ),
      // Use IP address of your droplet below
      '000.00.000.00' =&gt; array(
  
          //'siteUrl' =&gt; 'http://000.00.000.00/',
  
          'environmentVariables' =&gt; array(
              'basePath' =&gt; '/var/www/html/',
              'siteUrl'  =&gt; 'http://000.00.000.00/',
          ),
          // Default Week Start Day (0 = Sunday, 1 = Monday...)
          'defaultWeekStartDay' =&gt; 0,
          // Enable CSRF Protection (recommended, will be enabled by default in Craft 3)
          'enableCsrfProtection' =&gt; true,
          // Whether "index.php" should be visible in URLs (true, false, "auto")
          'omitScriptNameInUrls' =&gt; 'auto',
          // Control Panel trigger word
          'cpTrigger' =&gt; 'admin',
          // Dev Mode (see https://craftcms.com/support/dev-mode)
          'devMode' =&gt; false,
      )
  );
  </code></pre>
  
  <p>Any help would be greatly appreciated!</p>
  
Tags: <database><config>
Title: Craft on digital ocean Ubuntu: Craft can’t connect to the database with the credentials in craft/config/db.php
ThreadText: # Craft on digital ocean Ubuntu: Craft can’t connect to the database with the credentials in craft/config/db.php
  
  (Asked by: username_0 on 2017-09-21)
  
  I have been working locally on MAMP and now have deployed the site to Digital Ocean using this [guide](https://deploybot.com/guides/deploy-craft-cms-to-digitalocean).
  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/username_0/Sites/projectname/html/',
              'siteUrl'  => '//projectname:8888/html/',
          ),
          'testToEmailAddress' => 'email@email.com',
          // 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!
  
  **Tags:** database, config
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_1 on 2017-09-21. Score: 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
  
  
  ---
  
  ### Answer by username_0 on 2017-09-26. Score: 1
  
  Turns out this was a stupid mistake: I just had a white-space before
  
  Somehow it worked locally but not on the server.
  
  
  ---
  
  ### Answer by username_2 on 2017-09-21. Score: 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.
  
  > **Comments:**
  > **username_0**: 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.  
  > **username_2**: I've never used their LAMP image, see if you have something in /etc/apache2/sites-enabled  
  > **username_1**: 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.  
  
  ---
  
  