Back to .md Directory

Packerizing your config

Walks through installing Packer, authenticating with AWS, building an AMI, launching an EC2 instance, and connecting to a WordPress site.

May 2, 2026
0 downloads
1 views
ai rag
View source

What this file does

Walks through installing Packer, authenticating with AWS, building an AMI, launching an EC2 instance, and connecting to a WordPress site.

When to use it

  • You want to automate creation of a WordPress AMI with Packer
  • You need a quickstart for Packer with AWS and Ubuntu
  • You are following a beginner Linux/WordPress tutorial that uses Packer

Assumes this stack

PackerAWSUbuntuWordPressMySQL

Packerizing your config

  1. Install packer here.
  2. Read up on the docs for your cloud/platform/stack (we're using AWS here).
  3. You can use what's in this directory to get started!

Set up authentication

You'll need API access to your amazon account. To get this set up, log into your AWS Admin Console and navigate to: - IAM - Users - "Add Users" and pick a username - Select AWS Credential Type: "Access key - Programmatic access" - "Next - Permissions" -- add fine-grained permissions here, "Attach policies directly" and attaching AdministratorAccess will work, but it's not particularly safe or best practice. - After creating the IAM User, copy the "AWS Access Key ID" and "Secret Access key" that's displayed. The secret key will only be shown this once, so store it safely!

Export those keys in the shell where you'll be running packer commands, and you'll be good to go:

export AWS_ACCESS_KEY_ID="<YOUR_AWS_ACCESS_KEY_ID>"
export AWS_SECRET_ACCESS_KEY="<YOUR_AWS_SECRET_ACCESS_KEY>"

Run Packer

packer init .

# Format your packer code, if you've changed my example around
packer fmt .
packer validate .

Now you can build your AMI!

packer build wordpress-aws-ubuntu.pkr.hcl

Write down important output

This is an ugly hack which I made to keep things simple and easy to follow:

  • The autogenerated mysql password is echoed out to the shell AND written into /etc/packer-setup.log by default.

Use your instance!

  • Go to your AMIs -- they're region specific, so make sure your packer builder region and the one your're looking at in your AWS Console are the same.
  • Select the AMI you just built and click "Launch instance from AMI"
  • Configure EC2 Instance options like your SSH key and how big the storage volume should be
  • Launch the instance and wait for it to boot.
  • Grab your instance's public IP (click on the instance, then select the "networking" tab and look for "Public IPv4 address")
  • Connect via SSH! (username is ubuntu)

ssh ubuntu@yourInstanceIPAddress

Check out your webite!

Open the WordPress Installer in your Browser http://example.com/wp-admin/setup-config.php

Debugging

If you run into any errors after making modifications to this script, debug them! That's where all the learning really happens, anyway. Here are some resources:

TODO

  • get vars into the config files (they've got tutorialinux hardcoded in them)
  • compare and tune php.ini
  • mysql server root password and mysql_secure_installation
  • occasional failure to find mysql server... ==> packer-wordpress-tutorialinux-aws.amazon-ebs.ubuntu: E: Unable to locate package mysql-server

Basics Course

  • see this readme
  • decompose hands-on course scripts into scriptable chunks
  • base setup script (apt installs)
  • discuss MANUAL steps -- why are they manual? Can we automate or defer them?
    • noninteractive mysql install?
  • add vars to make it more configurable
  • config file templating using packer vars

What's inside

8 sections covering install, auth, build, output, launch, website check, debugging, and a TODO list with 3 code blocks

Change this for your project

  • Replace tutorialinux in TODO with your own project name
  • Replace http://example.com/wp-admin/setup-config.php with your instance's URL
  • Replace wordpress-aws-ubuntu.pkr.hcl with your actual Packer template filename

Where it goes

Keep it in your repository where the agent or team that needs it will read it.

Worth borrowing

  • Exporting AWS credentials as environment variables before running Packer
  • Using packer init, fmt, validate, and build as a standard workflow

Related Documents