amazon elastic beanstalk console

Scale WordPress Horizontally With Amazon Elastic Beanstalk

Trey Technical, Tutorial


Here at Tractus we are always impressed with how easy to use WordPress is as a CMS, which leads us to recommend WordPress to many of our clients as we discuss building their Website. WordPress is a very capable system, however, there seems to be a lack of information available on scaling WordPress in the cloud.

This guide will summarize our experience at Tractus in building WordPress systems that can scale infinitely using Amazon Cloud Services. The information here can easily be applied to other frameworks than WordPress but that is what we’ll be referencing throughout this guide. Using this guide you will be able to have a scalable WordPress system online within 30 minutes!

Local Development Setup

To start off, you need to get your WordPress installation all setup locally and committed to a local git repo. This shouldn’t be an issue for most people looking to setup this scalable system, as you most probably have a local installation already for development purposes. However, if this is not the case, we’ll walk through the process of getting setup locally.

To begin, we want to setup an empty git repository. To do this issue the following command on a Unix based OS with git installed:

git init <directory>
Where <directory> is the name of the project folder you’d like to have git create. This will create an empty project folder with git initialized in it (will create the .git folder).

Once you have your git repository setup, you can begin adding your application code.

To quickly setup a new WordPress installation in your new project directory download the latest version of WordPress and unzip it’s contents into your project directory.

Congratulations you now have a working website…Well, almost.

Wordpress Configuration Setup

We still need to configure WordPress so it knows how to connect to the RDS database that we’re going to setup. To do this, you need to rename the file wp-config-sample.php to wp-config.php and make a couple of edits inside of it. For our purposes we need to change the following lines:


/** The name of the database for WordPress */
define('DB_NAME', 'database_name_here');

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

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

/** MySQL hostname */
define('DB_HOST', 'localhost');

to instead read:


/** The name of the database for WordPress */
define('DB_NAME', $_SERVER['RDS_DB_NAME']);

/** MySQL database username */
define('DB_USER', $_SERVER['RDS_USERNAME']);

/** MySQL database password */
define('DB_PASSWORD', $_SERVER['RDS_PASSWORD']);

/** MySQL hostname */
define('DB_HOST', $_SERVER['RDS_HOSTNAME'] . ':' . $_SERVER['RDS_PORT']);

Scaling WordPress Media Files

Because we’re going to be running our application on AWS Elastic Beanstalk, which should be considered to have an ephemeral filesystem , we need to have some alternative way of storing uploaded files. Luckily the Open Source Community has solved this problem for us with the wonderful WordPress plugin Amazon S3 and Cloudfront which places our uploaded files in Amazon S3 for persistence and scalability.

Download the latest version of the plugin from the WordPress plugin repository and unzip it’s contents into the wp-content/plugins directory of your project.

Setting Up AWS

First things first, you need to sign up for an AWS account with Amazon. To do that, create a free account here.

Once you’ve created your account with Amazon you should have access to the AWS Dashboard, which is full of options but you simply want to select Elastic Beanstalk from the list. Whereupon you’ll find yourself faced with options to setup your web application. Follow along with the following steps to create your environment:

  • Click “Create a New Application”
  • Follow the prompts and fill out the details you desire for a “Web Server Environment” not a “Worker Environment”.
  • Make sure to select “PHP” under the “Predefined configuration” option.
  • Make sure to select “Load balancing, auto scaling” under the “Environment type” option.
  • Continue with the default options until you reach a point where it give the option of “Create an RDS DB Instance with this environment”.
  • Continue with the default options until you reach a point where it give the option of “Create an RDS DB Instance with this environment”.
  • Continue with the default options to finish creating your application. Make sure that when presented with the option MySQL is selected as the RDS DB Engine.

After you go through this process the magic Amazon Elves go to work to create a scalable platform for you to deploy your application to. After the system is setup, you should be able to visit the URL your chose in the setup process and see the AWS sample application running.

Deploying WordPress

To deploy your WordPress application to the cloud you use git as we hinted to before. You first need to install the AWS command line tools. The way that Elastic Beanstalk’s git deployment works is by creating a custom git command, to create this command you run the following script from the command line tools you just downloaded:

&lt;path_to_AWS_CLI&gt;/AWSDevTools/Linux/AWSDevTools-RepositorySetup.sh
from inside of your git repository. Upon doing this you will be asked a few questions, following which a new git command will be made available
git aws.push

This new command is great, but how does it know where to push the code to? To tell the command where to put the code you should create a folder called ‘.elasticbeanstalk’ and inside of this folder you should create a file called ‘config’. This file contains the configuration for your application that you created via the AWS console. The contents of this file should be:


&#091;global&#093;
ApplicationName=&lt;your_app_name&gt;
DevToolsEndpoint=git.elasticbeanstalk.us-east-1.amazonaws.com
EnvironmentName=&lt;your_environment_name&gt;
Region=&lt;your_app_region&gt;
where you should replace all items between < > with the appropriate values (i.e. <your_app_region> should be replaced with us-east-1 if that is your region).

NOTE: Make sure that your .elaticbeanstalk folder is added to your .gitignore!

Finally, you’re ready to commit your application and push it to AWS. To do so run the commands

git add -A
followed by
git commit -m "Initial Commit"
finally run
git aws.push
and your code will be packaged up and sent to AWS, when the code has been pushed and deployed you can visit and setup your new scalable WordPress installation in the cloud by visiting the URL your chose in the Elastic Beanstalk console.

Wordpress Installation Screen

Additional Details

Even though you’re up and running in the cloud, there are still a lot of things you should consider before taking your site live.

Firstly, don’t forget to configure your S3 plugin before uploading media. There’s nothing worse than uploading a bunch of photos and videos only to find out that 2 days later they’ve been deleted by Amazon’s Autoscaling policy. Although we haven’t got over how to setup this plugin, it shouldn’t be terribly difficult, but who knows maybe the next tutorial will be about setting up that plugin.

Secondly, please, please, please don’t assume that because you’re running behind a load balancer with autoscaling in place that you can conquer the world. It’s super important that you understand that there are plenty of places for bottlenecks to occur. Primarily, the database server which is connected to each of your web servers. For example, if you scale up to 4 web servers that means you’ll have 4 different servers all demanding your database server’s time.

Need Help?

We at Tractus are very adept at creating these scalable systems and would be thrilled to help you build your own. If the content of this guide is too technical, or you simply don’t have time to worry about setting up your own server please contact us so we can get you up and running in the cloud.

Are you already an expert at setting up servers but are not quite sure about developing your own custom site? Check out our affordable and flexible web development pricing and sign up today for Tractus to create your perfect custom site!

Share this Post

View More Articles


  • This field is for validation purposes and should be left unchanged.