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.

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

报告相同问题?

悬赏问题

  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真
  • ¥15 mars2d在vue3中的引入问题
  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面
  • ¥15 算法题:数的划分,用记忆化DFS做WA求调
  • ¥15 chatglm-6b应用到django项目中,模型加载失败
  • ¥15 CreateBitmapFromWicBitmap内存释放问题。
  • ¥30 win c++ socket
  • ¥15 C# datagridview 栏位进度