Using Amazon S3 for image hosting with a WordPress blog


The promise of Amazon S3 cloud hosting has been discussed extensively across the tech blogosphere, but for those of us who aren’t coders by trade, tapping into that potential does appear to be a serious challenge from the outside.

Regular readers would know that at times The Inquisitr isn’t as quick as it should be. Despite spending a small fortune on a Media Temple Nitro Server, our peak loads slow the site down, and more recently that’s meant the occasional database error as well. The next stage was a load server, but that would be a pretty penny on top of what we’re paying already. Thanks to some friendly advice from Wayne Robinson, there was another alternative: Amazon S3 for image hosting.

The key on our end is to bring the CPU load down (the memory has never once been taxed). Most of the load is SQL related, but add to that posts with larger images, and the constant bane of late of people hot linking our images, and combined we’ve managed to get CPU load out to as high as 70x what it should be.

As of yesterday, all new images being uploaded for posts, and a sizable portion of the template images (the ones I’ve dragged across) are served by Amazon. Early days yet, but I saw the CPU load hit 0.03x at one stage today (be it briefly) on a reasonable live traffic count, and I don’t remember ever seeing it go so low.

What you’ll need

If you’re using WordPress, head straight to the Amazon S3 plugin (here). At the time of writing it claims it’s only compatible up to WordPress 2.7, but it’s working fine on my 2.8.4 install. There’s also a WordPress Amazon S3 backup plugin available (here), you don’t need it for image hosting, but if you’ve ever been slack with backups, it’s a handy plugin to have.

You’ll also need Firefox plugin S3Fox (here) as well. I do most of my browsing on Safari, but I use Firefox for dev work. There’s probably an IE plugin/ add on out there as well, you’d have to look. The Firefox plugin gives you quick and easy access to your S3 account; if you’ve used an ftp program before you’ll immediately be able to use S3Fox.

Naturally you’ll need an Amazon S3 account. You can sign up here. If you’ve got an existing Amazon account, you use that to log in, and if you have a credit card on file with that account, you use that. Everyone raves about how cheap S3 is but I won’t profess to be able to explain how much it costs. What I do know is that 24 hours after signing up, we’ve racked up a bill of 56c. As we’ll be pushing more and more images onto the server this will go up, but if it ends up at $5-$10 a day, I won’t be the least bit concerned.

Set Up Round One

Once you’ve signed up to Amazon S3, you need to set it up to work with WordPress. First you need to create what Amazon calls a “bucket.” In layman’s terms, think of it as a folder on your Amazon S3 account. That’s where S3Fox comes in.

You have two options with S3Fox, you can go to a full view access via Tools in the Firefox menu, or you can click on the S3Fox icon at the bottom of Firefox which presents a smaller, limited version. It doesn’t matter at this point which one you pick, as long as you get access to your S3 account.

S3Fox requires three things for access: your Account Name, Access Key and Secret Key. All of those are available from S3 via the “security credentials option.” Cut and paste.

Once you’re in, it’s simply a matter of clicking on the “create directory” button which is a blue icon with a gold star on it, and naming your bucket. Note that you should name the bucket what you’d like your directory to be We’ll get to that part in a minute, but if you want to go with images.yoururl.com, name your bucket images.yoururl.com.

Setup Round 2: WP plugin settings

Once you’ve gotten to this point, you’re nearly there. You’ll have your S3 settings handy from setting up S3Fox, and you’ll need them again.

In WordPress, navigate to “Amazon S3” under the settings option. The first two options are easy: access key and secret code. After that you pick your bucket by drop down. In my experience, if you haven’t got a bucket set up, this just won’t show, so make sure you’ve set one up per the above instructions. After that I’ll go through step by step:

– Host name settings: if you want your images to appear at images.yoururl.com and not images.yoururl.com.s3.amazonsomething.com, click this option. However if you go this way, it requires you to setup a Cname entry on your domain. We’ll get to that part soon.
– File Uploads: check this if you want all WordPress uploads to go to your S3 account. The plugin gives you the option, and you also get a new button above the add new entry box if you’d rather pick between your server and S3 on a post by post basis.
– Expires Header:something to do with caching images. I could find no advice saying don’t check this, so I did. If you want to read more, there’s a link next to this option so you can find out more.
– File Permissions: you absolutely should check this otherwise your images won’t be publicly available. Uploads to S3 are defaulted to private…which is a pain in the neck if you’re uploading directly to S3 because you have to change file permissions each time. This option negates the need to do this with WordPress uploads.

Hit save, and that’s all there is to it.

Cname
You have a choice here, and this could be the most challenging point in the process if you want to go down this path. It’s easy to not go the cname route, although the problem there is that all your image uploads a linked into Amazon for the future, where as if you go cname, you can easily export out of Amazon at a later date.

Details on the cname settings are available on Amazon here. Depending on your setup, you may need to set this up with your domain name registrar or host. In my case, it was via MediaTemple’s control panel. Check with your host on how to set up.

And that’s all there is to it.

24 hours later and we haven’t had a hiccup yet. Mind you, if S3 goes down (which is extremely rare, but it has happened in the past) The Inquisitr is going to look mighty weird. But if it saves us money by not having to buy a new server, it’s a win all round.

Share this article: Using Amazon S3 for image hosting with a WordPress blog
More from Inquisitr