After years of manually upgrading my self-hosted WordPress installation, I decided it was finally time to apply some devops principles (namely automation) to this process.
This site runs on an EC2 instance on AWS, so I decided to use AWS Systems Manager (aka SSM). I started out by creating the following Command Document (which happens to be in YAML format because JSON is ugly):
--- schemaVersion: "2.2" description: "Download and install WordPress" mainSteps: - action: "aws:runShellScript" name: "example" inputs: runCommand: - "wget https://wordpress.org/latest.zip" - "mv latest.zip /var/www/html" - "cd /var/www/html" - "service httpd stop" - "unzip -o latest.zip" - "service httpd start" - "rm -f latest.zip"
The Command Document executes the bash commands in the runCommand section. It downloads the latest version of WordPress, stops Apache, unzips the files, restarts Apache, and then cleans up.
SSM uses an agent to carry out the bash commands. My instance runs Amazon Linux which comes with the agent preinstalled, so I didn’t need to install it.
Systems Manager can execute the Command Document at regular intervals to keep up with the typical WordPress release schedule of every 1-2 months. I can also trigger it manually if there’s a security or bugfix release I need.
To avoid catastrophe, I have the Amazon Data Lifecycle Manager for EBS Snapshots take daily snapshots of the instance, just in case something goes terribly wrong with an upgrade.Tags: automation, aws, devops, wordpress