duanjing9339 2019-05-10 22:25
浏览 122
已采纳

使用RDS建立数据库连接AWS Elastic Beanstalk时出错

I am trying to set up a simple Wordpress site using AWS Elastic Beanstalk with a disconnected RDS database (not part of the ELB instance in case I want to connect multiple sites to the DB) by roughly following this guide: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/php-hawordpress-tutorial.html.

However, I am getting the following error when loading up the Wordpress install:

Error establishing a database connection

So far I have tried to troubleshoot the issue by:

  1. Verifying that both the RDS and EC2 are on the same VPC with the same security group attached which has the proper inbound rules:

EC2 Security Group Inbound Rules RDS Security Group

  1. I have verified that the RDS is available like so:
nrb$ nc -zv <***masked-connection-string***> 3306
found 0 associations
found 1 connections:
     1: flags=82<CONNECTED,PREFERRED>
    outif en0
    src 192.168.20.149 port 58825
    dst 3.215.127.182 port 3306
    rank info not available
    TCP aux info available

Connection to <***masked-connection-string***> port 3306 [tcp/mysql] succeeded!
  1. I have verified that my EC2 can connect to the RDS by SSHing into it and using the mysql command and copy/pasting my env variables to make sure there were no typos as recommended by @littleforest, which successfully connected to the database.

  2. I have updated the sample PHP application that comes with AWS to output my env variables to make sure that the server is reading them. They outputted as they should.

My wp_config.php file looks like as recommeneded by the turtorial:

<?php
define('DB_NAME', $_SERVER['RDS_DB_NAME']);
define('DB_USER', $_SERVER['RDS_USERNAME']);
define('DB_PASSWORD', $_SERVER['RDS_PASSWORD']);
define('DB_HOST', $_SERVER['RDS_HOSTNAME'] . ':' . $_SERVER['RDS_PORT']);
define('DB_CHARSET', 'utf8');
define('DB_COLLATE', '');
define('AUTH_KEY',         $_SERVER['AUTH_KEY']);
define('SECURE_AUTH_KEY',  $_SERVER['SECURE_AUTH_KEY']);
define('LOGGED_IN_KEY',    $_SERVER['LOGGED_IN_KEY']);
define('NONCE_KEY',        $_SERVER['NONCE_KEY']);
define('AUTH_SALT',        $_SERVER['AUTH_SALT']);
define('SECURE_AUTH_SALT', $_SERVER['SECURE_AUTH_SALT']);
define('LOGGED_IN_SALT',   $_SERVER['LOGGED_IN_SALT']);
define('NONCE_SALT',       $_SERVER['NONCE_SALT']);
$table_prefix  = 'wp_';
define('WP_DEBUG', false);
if ( !defined('ABSPATH') )
    define('ABSPATH', dirname(__FILE__) . '/');
require_once(ABSPATH . 'wp-settings.php');

And in the config > software of my Elastic Beanstalk, I have verified these variables:

  • RDS_DB_NAME
  • RDS_HOSTNAME
  • RDS_PASSWORD
  • RDS_PORT
  • RDS_USERNAME

I know there is something stupid that I am missing which an AWS guru is going to catch right away, but this is driving me nuts.

  • 写回答

1条回答 默认 最新

  • duanqiang2617 2019-05-17 21:37
    关注

    Alright! After a few migraines and screaming at my keyboard, I have figured out what was going on.

    Since I was able to connect to the RDS server via SSH, I assumed that the problem had to be with Wordpress. Sure enough, when I turned on DEBUG mode, Wordpress could not find my database on the RDS server.

    It turns out when you set up an RDS the DB instance ID is not the DB name. However, even when specifying a name under the advanced config options, RDS never setup that DB on launch.

    So to solve this problem, I had to:

    1. SSH into my EC2 Instance and connect to RDS using the mysql command as @littleforest suggested
    2. Create the database inside the mysql console.

    Then once I verified the DB existed in the mysql console, I was able to run the famous 5 minute Wordpress installation.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 深度学习运行代码直接中断
  • ¥15 关于#单片机#的问题,请各位专家解答!
  • ¥15 关于#单片机#的问题,请各位专家解答!
  • ¥20 需要完整的共散射点成像代码
  • ¥15 编写vba代码实现数据录入工作
  • ¥15 做过TCL海信电视小米电视相关影视会员软件私我
  • ¥15 Mapreduce是正常的,在运行其他jar包时并没有任何问题,只是在做LogCount.jar 时出的问题。如图所示
  • ¥15 ImportError: DLL load failed while importing _iterative: 找不到指定的模块。
  • ¥15 如何通过交互分析得出某高危患者对放疗获益更多
  • ¥15 相关性分析中,p<0.05, r=0.29,怎么评价相关性呢