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:
- Verifying that both the RDS and EC2 are on the same VPC with the same security group attached which has the proper inbound rules:
- 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 220.127.116.11 port 3306 rank info not available TCP aux info available Connection to <***masked-connection-string***> port 3306 [tcp/mysql] succeeded!
I have verified that my EC2 can connect to the RDS by SSHing into it and using the
mysqlcommand and copy/pasting my env variables to make sure there were no typos as recommended by @littleforest, which successfully connected to the database.
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:
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.