Alex Borsody
Alex Borsody

Reputation: 2060

Can not Connect Drupal to DB only on AWS

uploaded an existing drupal codebase to a virtual host set up on AWS. it is showing "can not connect to database"

I created database "dbname" and can connect fine through ssh. But can not get settings.php to connect. As far as I can tell the mysql user has all needed permissions to access the db remotely.

what I have

$db_url = 'mysql://username:[email protected]/dbname';

Here is example of settings.php with a drupal 7 site of ours that connects fine

$databases = array (
  'default' => 
  array (
    'default' => 
    array (
      'database' => 'dbname',
      'username' => 'dbuser',
      'password' => 'password',
      'host' => 'us-west-rds.amazonaws.com',
      'port' => '3306',
      'driver' => 'mysql',
      'prefix' => '',
    ),
  ),
);

Upvotes: 0

Views: 1724

Answers (4)

Brian Uckert
Brian Uckert

Reputation: 1

You might also want to check...

setsebool httpd_can_network_connect_db on

Upvotes: -1

Ryan Parman
Ryan Parman

Reputation: 6945

You're pointing at the wrong hostname.

'host' => 'us-west-rds.amazonaws.com'

Each individual database instance will have it's own hostname. You can look it up in the AWS Console. The one you're currently pointing to looks like you intended to point to the RDS web service API endpoint.

Upvotes: 0

j0nes
j0nes

Reputation: 8109

There are several things to check:

  • do you have the security group open to allow access from your server (as said by Bob Kinney in the other answer)?
  • do you have a firewall set up on your server that prevents connecting to your RDS instance?
  • does your user have sufficient rights to connect to your database?

The easiest way to debug this is to use the console mysql command and try to connect to your instance from there:

mysql dbname -u username -p password -h db01b2.ck1dmcn6kfws.us-west-1.rds.amazonaws.com

If this does not work, check the points given above. If this works and does not work in Drupal only, check your PHP code and/or Drupal config.

Upvotes: 4

Bob Kinney
Bob Kinney

Reputation: 9030

Sounds like you may not have set up your security groups to allow access from your EC2 instances. You'll want to make sure your DB security group has an ingress rule to allow traffic from your EC2 instance/security group.

How do I control network access to my DB Instance(s)?

Upvotes: 2

Related Questions