Skip to main content

Amazon Web Services

Automation with AWS for WordPress, Drupal & Magento Applications

Objective

Automatic installation and configuration solutions for WordPress, Drupal, and Magento applications using AWS CloudFormation infrastructure orchestration and content management tools like Puppet, Ansible, or Chef. The infrastructure as code (IaC) solution should follow architecture best practices such as setting up the database in a private segment, secure authentication, and provisioning. It should also have the system configuration optimization for web, database, and ready-to-go solutions.

A CloudFormation template accepts the user inputs as parameters where needed – for example admin credentials for WordPress, and URL and admin credentials for Magento. The template will also set up Amazon Virtual Private Cloud (VPC) in AWS and create the infrastructure as per best practices. It should also create subnets and launch instances. It will pull required code from the code repository to set up the application or use Amazon S3 for this purpose. Lastly, it will perform optimization using Puppet and set up the base WordPress setup.

Overview

Here we are using WordPress as a base setup, but this is not limited to WordPress – you can go with Magento and Drupal with small changes. The solution is prepared to accomplish automatic setup and I tried to make it simple as possible. I also wanted to take the opportunity to utilize different techniques that show the various possible ways to integrate different pieces of components required for WordPress application setup and deployment.

Component Involves

  • Amazon S3 (code storage)
  • AWS CloudFormation Template (YAML)
  • Puppet 5.0 (Masterless Setup)
  • Nginx
  • PHP-FPM
  • MySQL
  • WP-CLI
  • WordPress

Prerequisites

The solutions are well tested in the US West region (Oregon, [us-west-2]) with Amazon Linux 1 AMIs and prepared to work seamlessly with AWS US East (N. Virginia, [us-east-1]). It can also work for US West (N. California, [us-west-1]) with a small change. The solutions is fully customizable as per need.

Before you start, there are a couple of prerequisites.

  • KeyName:
    • Please set up a SSH key pair in your AWS account (CF Input).
  • S3 Bucket:
    • Please create a “code pull” S3 bucket (it’s hardcoded if you want to use S3)
    • Suggestion: You can use GIT to pull code with a small change in “userdata” of the instance in the CF template.
  • AWS Credentials (optional):
    • I hardcoded the provided AWS credentials to configure AWS-CLI.
    • Note: With a small CF Parameter change, you can input the AWS credentials.
    • Suggestion: You can add an IAM role to the instance and provide input with CF.

Note: Make sure AWS Credentials have access to the S3 bucket.

Solutions

Once the prerequisites have been set, the AWS CloudFormation template is going to accept inputs to set WordPress and provide CF output with the accessible domain name URL of the WordPress application. The CloudFormation template is going to perform the following activity:

CloudFormation Stack Flow

  • Collect inputs.
  • Provision VPC, public, and private subnets.
  • Provision web and DB instances (t2.small/t2.micro type) as per input (Preferred t2.small) and deploy them into the private and public subnets respectively.
  • Provision EIPs for the NAT gateway and the CM/web instance.
  • Setup security groups to make connectivity for communication.
  • Install the Puppet agent for the Puppet MasterLess setup and pull the required custom puppet module from the S3 bucket (code pull).
    • I used ready-to-go Puppet modules instead, created custom modules configuration and placed named devopshv1_AWSLinux1.tar.gz into the code repository.
  • Run Puppet module installation and setup Nginx and PHP-FPM (PHP extension) and perform configurations of Nginx and PHP_FPM.
    • You can modify Nginx and PHP-FPM configuration based on system RAM as a part of optimization in the Puppet module.
  • Use the cfn-init script CF stack to set up WordPress configuration.
  • Use the instance “userdata” configured WP-CLI to install the WP database and finalize WP setup.
  • Stack output provides the WP application access points URL.

Architecture Map

Steps to Create a Setup

  1. Set prerequisites Keypair (KeyName) and S3 Bucket (code pull).
  2. Log in to the AWS account and create the CloudFormation stack using
  3. Upload code to the S3 bucket, including devopshv1_AWSLinux1.tar.gz file (solution extract it).
  4. Create the CloudFormation stack in the Oregon region.
  5. Supply input to the CF template.
  6. The stack template will take a few minutes to provision the AWS resource and WP configurations.
  7. Check the stack output to gain the access domain URL or public IP.

Final WP Application Output

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.