Categories
Geek Speak

Updating WordPress on AWS Elastic Beanstalk

If you have gone through the bother of building WordPress on AWS Elastic Beanstalk and EFS, you probably are not looking forward to the next WordPress update. The simple answer is to do things backwards. Update your server then use the update to update your repo then use your updated repo to update your server. Simple

  1. Login to the wp-admin page for your site
  2. Update WordPress
  3. Update Your Plugins
  4. Update Your Theme
  5. Clean Up Any Lint in Your WordPress
  6. Make a tar of your WordPress directory
  7. scp the tar to Your Workstation
  8. Uncompress it to a temporary directory
  9. Delete All of the Files in Your Update from Your CodeCommit Repo
  10. Copy Everything in Your Update to Your Repo
  11. git add –all
  12. git commit -am “wordpress update”
  13. git push
  14. eb deploy

I wrote a script to do this and put it in the repo so I would always have it. My script looks like this:

# !/bin/bash
# this file is present in the local document root, it must be run from that location
# get the server name from AWS
myserver=$(aws ec2 describe-instances –region us-east-1 –profile MYPROFILE | grep -m 1 PublicDns | awk ‘{print $2}’ | sed -e ‘s/\”//g’ -e’s/\,//’)

# run a command on the server to bundle up the Elastic Beanstalk document root
ssh -i ~/.ssh/MYCERT.pem ec2-user@$myserver -t ‘tar -czvf ~/wp-new.tar.gz -C /var/app/current/ .’

# copy the bundle from the server to the local workstation
scp -i ~/.ssh/MYCERT.pem ec2-user@$myserver:wp-new.tar.gz ~/Downloads

# decompress the image in the Downloads directory
mkdir ~/Downloads/wp-new
tar -C ~/Downloads/wp-new -xvzf ~/Downloads/wp-new.tar.gz

# delete all of the files found in the extract from the local repository
ls -1 ~/Downloads/wp-new | xargs /bin/rm -rf

# copy the server document root into the local repository
cp -R ~/Downloads/wp-new/ .

# remove the upload directory to keep the deploy from failing
rm -f wp-content/update

# the following lines are only needed for Code Commit implementations
ts=/bin/date +%Y%m%d%H%M
git add –all
git commit -am “wordpress update $ts”

#clean up
rm -rf ~/Downloads/wp-new
rm -f ~/Downloads/wp-new.tar.gz

# the following line pushes the update to the elastic beanstalk instance
eb deploy

Leave a Reply