Search code examples
amazon-web-servicesamazon-ec2drupaldrupal-6

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' => '',
    ),
  ),
);

Solution

  • 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.