This is a simple WordPress website deployed on Elastic Beanstalk which automatically scale web apps. The Storage solution is a shared storage using Amazon Elastic File System (EFS). The database solution (Amazon RDS) will be external to the Elastic Beanstalk, making it easy for multiple environments to connect to the DB. Another benefit is that you can easily perform blue/green deployment without affecting the database.
Since this is not in Prod, I'll be using the Dev/Test
template but do note that if you're in Prod then you should use the Production template.
- I'm selecting the Multi-AZ DB instance... However, note that there is now a new
Deployment Option
: Multi-AZ DB Cluster which let's you create a primary and 2 readable standby instances, each in a different AZ! With this new option, your standby supports and can serve read workloads! 👏 - Do take note of your Master username & password. You'll need them to connect to the DB later.
- In the Connectivity options, take note of your
VPC
, you'd need to place your app in the sameVPC
later on so they're within the same network. Also, if you plan to connect to your DB instance outside of thisVPC
network, then you need to select the option to make it Publicly Accessible. When configuring your Security Group, if you set it Publicly accessible, then configure inbound rules to allow the IP or block of IPs you want to have access and of course, allow access from the application (preferrably via the app SG).
Do this part in CloudShell
so your files are readily accessible from within AWS
- Download the WP files using:
curl https://wordpress.org/wordpress-6.1.1.tar.gz -o wordpress.tar.gz
- Download the config files from the sample repo:
wget https://github.com/aws-samples/eb-php-wordpress/releases/download/v1.1/eb-php-wordpress-v1.zip
- Extract the WordPress files.
tar -xvf wordpress.tar.gz
When it's done extracting, it creates a new directorywordpress
and moves the extracted contents here. - You can skip this and
cd wordpress
. I chose to rename minemv wordpress wp-bnstlk
cd wp-bnstlk
-
You can use this pre-configured URL to create your app.
-
For Platform, select
PHP
and accept defaults > Review and Launch > Create app. It takes a few minutes as it is creating other resources like your: -
CloudWatch alarms, Security Groups, Domain name (if you prefer, you can choose your domain name just before Review and Launch, I chose to leave mine blank so I'll get an auto-generated domain.)
-
In your environment, under Configuration, Edit the Instances option. Edit EC2 SG to make sure that it's letting the DB traffic on Port 3306 from the rds-SG Security Group.
-
Still in Configuration, navigate to Software this time > Edit > Scroll down to Environment Properties and enter the following then Apply:
Name Property RDS_HOSTNAME
This is the Endpoint of your DB instance RDS_DB_NAME
The name of the database you create RDS_PASSWORD
The password you created when setting up your RDS instance RDS_USERNAME
The username you created when setting up your RDS instance RDS_PORT
MySQL instance will run on Port 3306 -
When you navigate to your app URL, you should get a page that looks like this:
-
Create source bundle using
zip ../wp-bnstlk.zip -r * .[^.]*
-
Download the created source bundle
wp-bnstlk.zip
. Go to Actions > Download file and provide the file path from CloudShell -
In the Elastic Beanstalk env in the Management Console, click on Upload and deploy > upload the zip file you just downloaded.
-
Open website URL and perform the standard installation. Use the same settings previously configured for the Environment properties.
-
Navigate to your app URL in Elastic Beanstalk. If all works correctly, you should be prompted with the installation for WP.
-
Before continuing here, remember how we created an RDS instance earlier, we need to create a DB in that instance. You can connect to the DB instance using MySQL Workbench
-
create database everlydb;
-
Now we have a database we can use to configure the settings:
-
The remaining steps are pretty easy, just accept defaults and enter required information for WordPress to finish installing. If you want to, you can edit WP and use it with the database but we won't be going into that. The focus here is to show how to set up a highly available website in AWS. We have one more thing to do to ensure our setup is robust enough to handle high traffic, AutoScaling!
To ensure our setup can handle high traffic spikes, we will configure AutoScaling to have a minimum of 2 instances running at any given time.
- Back in the Environment, Configuration, edit Capacity, at the very top, update Auto scaling group Min from 1 to 2 > Apply.
Reference AWS Guide 🙌
Thank you!