Implementing Amazon S3 for WordPress Blogs

Note: Since writing this, we’ve since migrated to WPEngine with a Content Delivery Network powered By MaxCDN, a much faster CDN than Amazon.

Unless you are on a premium, enterprise hosting platform, it’s difficult to get enterprise performance with a CMS like WordPress. Load sharing, backups, redundancy, replication, and content delivery don’t come cheap.

Many IT representatives view platforms like WordPress and use them because they’re free. Free is relative, though. Put WordPress on a typical hosting infrastructure and a couple hundred simultaneous users can bring your site to a grinding halt. To assist in my blog’s performance, this week I modified my installation of WordPress push all of the graphics from Amazon S3 (Amazon Simple Storage Service). This leaves my server to simply push HTML via PHP/MySQL.

Amazon S3 provides a simple web services interface that can be used to store and retrieve any amount of data, at any time, from anywhere on the web. It gives any developer access to the same highly scalable, reliable, fast, inexpensive data storage infrastructure that Amazon uses to run its own global network of web sites. The service aims to maximize benefits of scale and to pass those benefits on to developers.

To convert the site for Amazon S3 took a bit of work, but here are the basics:

  1. Sign up for Amazon Web Services.
  2. Load the Firefox Add-on for S3. This provides you a great interface for managing content in S3.
  3. Add a bucket, in this case I added images.marketingtechblog.com.
  4. Add a CNAME to your Domain Registrar to point a subdomain from your site to Amazon S3 for virtual hosting.
  5. Download and install the WordPress plugin for Amazon S3.
  6. Set your AWS Access Key ID and Secret Key and click update.
  7. Select the subdomain/bucket you created above for the Use this bucket setting.

wp-amazon-s3-settings.png

The next steps were the fun part! I didn’t want to just serve future content from S3, I wanted to serve all content, including ads, themes, and past media files.

  1. I created folders for ads, themes, and uploads in my bucket on S3.
  2. I backed up all my current content (image and media files) to the applicable folders.
  3. I modified my CSS file in my theme to pull all images from images.marketingtechblog.com/themes.
  4. I did a MySQL search and replace and updated every reference to media content to be displayed from the S3 subdomain.
  5. I updated all image references for ads to be displayed from the ads folder on the S3 subdomain.

From here on out, I simply need to upload media to S3 rather than using the default image upload dialogue for WordPress. The plugin does a fantastic job in putting an S3 icon in the same location of Upload/Insert icons in the WordPress admin.

Moving all of the data and running on S3 for a couple days now has resulted in $0.12 in S3 charges, so I’m not concerned about the fees involved – perhaps a few dollars a month is what it will cost. On the plus side, if I get a ton of visitors, I should be able to handle many more than the current platform handles. My site is loading the home page in about 40% of the time that it used to, so I’m quite happy with the move!

The nicest thing about this move is that it didn’t actually require any development!