Skip to main content

Lab 8 - Elastic Beanstalk

Overview

This week's lab will cover the following:

  • Creating a new RDS
  • Configuring Elastic Beanstalk
  • Installing and configuring Wordpress

When you have installed Wordpress previously, you simply uploaded the source code and the first time you load the webpage, provided the database connector information. However, Elastic Beanstalk applications are meant to be disposable.

Normally, when you add that database connector info, it is saved in a file called wp-config.php on the webserver VM. This is fine for a traditional setup. However, in Elastic Beanstalk, changes made to static HTML or PHP are not saved if the Beanstalk application restarts, which it will do often. Whenever the application restarts, it will reload from the source zip file and the original, empty connector file. If you did this the traditional way, you'd have to constantly re-enter your DB connector info every time you started up your Learner Lab environment.

We could add the DB connector info to wp-config.php manually before we upload the source code, but there's a much better way.

We use environment variables to allow us to put all the info in the Elastic Beanstalk application wizard directly. That way, every time the application restarts and reloads from the source code zip, it'll then read our saved connector information from AWS itself. Read below for details and steps.

Note: All other information, like the Wordpress website name, users, theme settings, blog posts, etc., are saved in the actual database you created in RDS. This database does not get reset when the Elastic Beanstalk application restarts, so your actual blog data will remain intact.

Investigation 1: Creating a RDS instance

Start your session in the Learner Lab by clicking on the Start Lab button. Once the red dot has turned green, click on it to enter the Learner Lab and access the AWS Console interface. You are going to create a new RDS instance.

From the Console Home navigate to Database > Aurora and RDS. See the following screenshot for reference.

Relational Database

Click Create database (part way down the screen). Use the following options.

  1. Standard create
  2. Engine type: MariaDB
  3. Engine Version: MariaDB 11.4.5 (or current latest version available)
  4. Templates: Sandbox
  5. DB instance identifier: wordpress-elasticbeanstalk
  6. Master username: admin
  7. Credentials management: Self Managed
  8. Auto generate a password: Checked
  9. DB instance class: db.t3.micro
  10. Allocated storage: 5 GiB
  11. Enable storage autoscaling: Unchecked
  12. Virtual private cloud (VPC): Wordpress VPC
  13. DB subnet group: Select the subnet group from Lab 5, it should be the auto selected one
  14. Public access: No
  15. VPC security group: Choose existing
  16. Existing VPC security groups:
    1. Remove default VPC
    2. Add Wordpress Database SG (look to see that it's there below the dropdown after you select it)
  17. Availability Zone: us-east-1a
  18. Monitoring > Enable Enhanced monitoring: Accept the default
  19. Below the Monitoring section, Additional configuration > Initial database name: wordpress (Write the database name down! You will need this later.)
  20. Enable automated backups: Unchecked
  21. Enable encryption: Unchecked

Click Create database.

Close the popup window.

This will take a few minutes to create. Once the database has finished creating, click on the View connection details button by the green success message at the top of the page. This gives you your database password.

Store the following connection information about your RDS instance in your lab logbook or a saved document. You'll need it later:

  1. Endpoint
  2. Initial database name
  3. Master username
  4. Master password

Connecting to your database from www

Login to your www instance, and issue the following command to connect to your database. Be sure to substitute the credentials you wrote down earlier.

mysql -u admin -h **endpoint** -p

Enter your Master password when prompted. You should see the following screen indicating a successful connection.

MariaDB connected

Issue the following command to display the databases.

show databases;

Disconnect from the database.

quit;

Investigation 2: Elastic Beanstalk

Navigate to Compute > Elastic Beanstalk. See the following screenshot for reference.

Elastic Beanstalk

Click Create application, and use the following settings:

Environment Tier

Select: Web server environment

Application information

  1. Application name: wordpress

Environment information

  1. Environment name: Wordpress-env

Platform

  1. Ensure Managed platform checked
  2. Platform: PHP
  3. Platform branch: PHP 8.4 (or current latest)
  4. Application code: Upload your code
  5. Version label: wordpress-6.7.2 (Use the version from your zip filename)
  6. Public S3 URL: https://username-wordpress.s3.us-east-1.amazonaws.com/wordpress-6.8.1-modded.zip (Where username is your Seneca username)

Presets

  1. Presets: Single instance (free tier eligible)

Click next

Configure Service Access

Select: Use an existing service role

  1. Service role: LabRole
  2. EC2 instance profile: LabInstanceProfile
  3. EC2 key pair: vockey

Click next

Set up networking, database and tags

  1. VPC: Wordpress VPC

Instance Settings

  1. Public IP address Activated: Checked
  2. Instance subnets: Public Subnet 1, Public Subnet 2 (both checked)

Database settings

  1. Database subnets: Private Subnet 1, Private Subnet 2 (both checked)

Click Enable database

  1. Username: admin
  2. Password: The password you copied and wrote down earlier

Click next

Configure instance traffic and scaling

  1. EC2 Security Groups: Wordpress Website SG & Wordpress Database SG (both checked)
  2. Leave the rest default

Click next

Configure updates, monitoring and logging

Monitoring

  1. System: Basic

Managed platform updates

  1. Managed updates: Unchecked

Email notifications

  1. Email notification: Add your Seneca email

Platform Software

Before beginning this section, you will need two things:

  1. Your database connector information (you saved this, right?)
  2. Randomly generated auth keys and salts from here: https://api.wordpress.org/secret-key/1.1/salt/ (it's a good idea to save these in a text file, too)

Container Options

  1. Proxy server: Apache
  2. Document root: /wordpress
  3. Click Add environment property and add the following Environment properties
    1. DB_HOST: your RDS database URL
    2. DB_NAME: wordpress
    3. DB_USER: admin
    4. DB_PASSWORD: your auto-generated database password
    5. AUTH_KEY: (use gathered info from salt page)
    6. SECURE_AUTH_KEY: (use gathered info from salt page)
    7. LOGGED_IN_KEY: (use gathered info from salt page)
    8. NONCE_KEY: (use gathered info from salt page)
    9. AUTH_SALT: (use gathered info from salt page)
    10. SECURE_AUTH_SALT: (use gathered info from salt page)
    11. LOGGED_IN_SALT: (use gathered info from salt page)
    12. NONCE_SALT: (use gathered info from salt page)

Hint: None of these values should have single quotes in them. (i.e. ')

Image: Adding database connector information, auth keys and salts to your Elastic Beanstalk application as static Environment Variables. Figure 2: Adding database connector information, auth keys and salts to your Elastic Beanstalk application as static Environment Variables.

Click next.

Review options

Review all settings and ensure they match the instructions above. Once you hit Create, the application will take several minutes to create.

Create the application.

click Submit when ready.

While you wait for the creation to complete, check your e-mail to confirm your notification subscription.

If your application fails to build, double check your wp-config.php configuration file for syntax errors. Additionally, make sure when you rezipped the file you only select the wordpress folder, not the main folder.

Investigation 3: Accessing Wordpress

Open the URL presented in the Wordpress EBS instance and begin the site setup.

Site Information

Set the following site information:

  1. Site Title: Your name's blog
  2. Username: yourSenecaUsername
  3. Password: Choose a strong password (do not reuse the DB password!)
  4. Your Email: yourSenecaEmailAddress
  5. Search engine visibility: Unchecked

If you get a message indicating a failure to connect, make sure you zipped the wordpress folder and it's contents only. You can rezip the file and click Upload and deploy if necessary.

Blog Post:

Add a blog post detailing the following:

  • What did you think of this lab?
  • What was the most difficult part for you?
  • What was the easiest part for you?

Lab 8 Sign-Off (Show Instructor)

Take screenshots showing the following:

  • Your blog post.

Shutting down your database:

  • Naviage to Aurora and RDS > Databses.
  • Select the radio button beside wordpress-db
  • Click on Actions > Stop temporarily

This will shutdown your database for 7 days and pause billing. You may need to repeat this.

Exploration Questions

  1. What is Elastic Beanstalk?
  2. How is this lab similar to the wordpress install in Lab 5? How is it different?