Have Your Wordpress Static Files On Amazon S3

🦖 This post was published in 2013 and is most likely outdated.

You can have many reasons to host your Wordpress static files on Amazon S3: your local storage is not persistent, you want to unload your webserver, you have multiple Wordpress server instances sharing the same satic files, S3 is cheaper than EBS, etc.

First, get an Amazon S3 account. On Amazon S3 you can have sorts of drives (buckets) in the cloud that you can use to store data. When creating your S3 account, record your Access Key ID and Secret Access Key, they will be needed to connect your Wordpress to your S3.

S3 bucket

Once you created your S3 account, go on S3 at console.aws.console.com/s3 and create a new bucket for your blog that you can name whatever you want. I’ll name mine say my-blog-drink-coffee. When you’re done you should see your new bucket in your bucket list:

As we want to serve our Wordpress static files from that bucket, we have to make all content publicly available. Select your bucket and click on “Edit bucket policy”, paste this policy (which is making everything public) replacing my-blog-drink-coffee by your bucket name and save.

{
  "Version": "2008-10-17",
  "Statement": [ {
      "Sid": "AllowPublicRead",
      "Effect": "Allow",
      "Principal": { "AWS": "*" },
      "Action": "s3:GetObject",
      "Resource": "arn:aws:s3:::my-blog-drink-coffee/*"
  } ]
}

Wordpress S3 plugin

Now, we are going to tell our Worpress to store static files (medias, plugins and themes) on S3 instead of the local server. In the plugin page, click on “Add new”, search the plugin “Amazon S3 for WordPress with CloudFront”, install it and activate it. In the newly created section “Amazon S3”, under “Settings”, fill in the values like this:

  • Paste your Access Key ID and Secret Access Key from your Amazon account
  • Choose the bucket you just created in the bucket list
  • Select “File uploads” and “File permissions”

Save and you’re all set.

Test your configuration

Create a new post and add any image to it (upload it from your computer). Go on S3 at console.aws.console.com/s3, you should see the file in your bucket (under the directory wp-content). The image should display correctly in your post when you publish it and when you look at the source of your page, the URL of the image should be something like

http://my-blog-drink-coffee.s3.amazonaws.com/...

Comments