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:
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!
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.
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.
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:
mysql
command as @littleforest suggestedThen once I verified the DB existed in the mysql console, I was able to run the famous 5 minute Wordpress installation.