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 port 58825
    dst 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:

define('DB_NAME', $_SERVER['RDS_DB_NAME']);
define('DB_HOST', $_SERVER['RDS_HOSTNAME'] . ':' . $_SERVER['RDS_PORT']);
define('DB_CHARSET', 'utf8');
define('DB_COLLATE', '');
define('AUTH_KEY',         $_SERVER['AUTH_KEY']);
define('NONCE_KEY',        $_SERVER['NONCE_KEY']);
define('AUTH_SALT',        $_SERVER['AUTH_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:


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.

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



    • ¥15 shopify网站提速
    • ¥15 深海控制器DSE7320MKII和博世ECU间can通讯知识
    • ¥15 Ru的复折射率用于FDTD 200nm到1200nm
    • ¥15 使用Fiddler抓包,textview的乱码如何解决
    • ¥50 trio连接驱动器报错
    • ¥15 有谁懂nhanes的权重计算啊
    • ¥15 欧姆龙PLC 电机控制 限位
    • ¥30 如何处理shell命令接收到的视频流并实时播放出来
    • ¥15 虚心请教C#的代码优化问题
    • ¥15 有偿求做台风过境全过程模拟仿真