Managing Multiple WordPress Environments Amazon EC2, Elastic Beanstalk, & RDS

We were recently asked on our Deploying WordPress to Amazon Web Services AWS EC2 and RDS via ElasticBeanstalk post how to easily manage multiple environments and multiple databases with one codebase. The answer with Amazon’s Elasticbeanstalk is pretty straightforward.

Step 1:

Launch a new environment within the same application.

Untitled-1

Step 2:

Once that new environment is in the green state and finished deploying, click on it. Then once inside the new environment overview in the AWS Console, click Configuration on the left and then the Cog icon next to Software Configuration. Near the bottom find PARAM1 and set its value to STAGING (or PRODUCTION). We usually opt for finding your production environment regardless of the newest environment created and setting its PARAM1 to PRODUCTION. You don’t have to set PARAM1 for STAGING although we highly recommend it for organization.

Click Save.

Step 3:

Go create another database within RDS if you didn’t do so in step 1. Get the information from this new database that you’ll use in the next step.

Step 4:

Now in your wp-config.php file we need to setup an IF / ELSE statement like so:


if ( file_exists( dirname( __FILE__ ) . '/local-config.php' ) ) { 

	include( dirname( __FILE__ ) . '/local-config.php' ); 

} else if(isset($_SERVER['PARAM1']) && $_SERVER['PARAM1'] === "PRODUCTION"){

	/** MySQL database name */

	define('DB_NAME', 'productiondatabase');

	/** MySQL database username */
	define('DB_USER', 'productionusername');

	/** MySQL database password */
	define('DB_PASSWORD', 'productionpassword');

	/** MySQL hostname */
	define('DB_HOST', 'production.randomhostname.givenFromRDS.us-east-1.rds.amazonaws.com');

}else{

	/** MySQL database name */

	define('DB_NAME', 'stagingdatabase');

	/** MySQL database username */
	define('DB_USER', 'stagingusername');

	/** MySQL database password */
	define('DB_PASSWORD', 'stagingpassword');

	/** MySQL hostname */
	define('DB_HOST', 'staging.randomhostname.givenFromRDS.us-east-1.rds.amazonaws.com');

}

Conclusion

One codebase, one GIT repo, limitless number of environements.

As always, feel free to ask any questions or let us know if you have a better way.

{o}
Otreva is a custom software product development company focusing on user experience, responsive web development, & mobile application development.

Interested in seeing what it costs to build an app?

Start Quote See Stats
224 Wyoming Ave. #100
Scranton, PA 18503

You've found the secret footer!

Tweets about @Otreva

Or check us out on:

Shopify Experts
Awwwards