• 0
  • March 16, 2010

Share!

Amazon S3 and WordPress

Your website suddendly receives a lot of traffic? That might crash your server or your account might be temporaly suspended, depending on your hosting plan and conditions.

Here is a rather cheap solution to avoid bandwidth consumption and server load with a WordPress installation.

I am running a photoblog diachronie that from time to time enjoys peak of visitors from StumbleUpon. My server isn’t built to support 10’000 visitors a day. It crashes several times, thus leaving the other websites running on the server in the blue also.

There are several steps that you can take before upgrading to a more expensive hosting plan, especially, if like me, you don’t make business with your site and don’t care about the traffic.

Amazon CloudFront

Amazon CloudFront is Amazon’s CDN services. The idea here is to put your WordPress blog and content on an Amazon S3 bucket. The advantages of the CDN is, among other things, that whether you’re in the US or EU, the server’s response will be the same.

You can use your blog without CloudFront, specially if your server is US based and your visitors are mostly from US. But, if you’re an european enjoying cheap US hosting services, the latency time is almost 200ms from Europe and for a page with many HTTP requests, you’ll will have to wait up to 10x the time than an US user.

Setting up Amazon S3

First, you need to have an Amazon Services account. Create one here if you don’t have one. The creation is free, but you’ll have to pay for the amount of data stored and the bandwidth. You can estimate the price here.

Note down your Access and Privates keys, you’ll need them both.

So much for the Amazon part.

Tools for accessing your buckets

You’ll need to create and access you buckets.

The two applications I’ve been using are Bucket Explorer and S3Fox. The former being a standalone application and the other a Firefox extension.

Both work pretty well and S3Fox suits most needs. I’ve bought BucketExplorer as it handles ACL recursive changes and directories synchronisation better than S3Fox.

Setting up S3Fox

First you need to enter your credentials. Click on manage accounts and fill in your access and private keys.

s3fox

Creating a bucket is not different from creating a directory. To access your bucket, it will simply be [bucket name].s3.amazonaws.com.
On the left part of S3Fox, right click on your newly created bucket and choose “manage distributions”.

bucket

Now, click on create distribution. This will actually create your CDN on CloudFront.

Choose a CNAME for your bucket. This will allow you to access your CDN via a clean URL like cnd.yourwebsite.com.

cdn

It will take a moment before your distribution is deployed.

Creating a CNAME DNS record

That’s the tricky part. Either you ask your host to do it, or you have access to the DNS records and can do it yourself. If you’re hosted in Mediatemple, this is easily done through their web interface.

Simply choose your domain and click on edit zone file. There, add a CNAME record. It might be a good idea to lower the TTL.

Point your chosen domain name to your CDN cloud.

mediatemple

You’re almost there.

Now on with the Worpdress part.

W3 Total cache plugin

The W3 Total Cache plugin is one of the best caching plugin you’ll find for WordPress. It is not specifically designed for Amazon services, but to optimize a WordPress installation and a CDN is part of the optimization.

I won’t go into all the details of this plugin, as my aim here was to show how to deploy your WordPress installations easily on a CloudFront.

First, get the plugin and install it. Second, you’ll need to give temporally permission to the wp-content folder and to your .htaccess file.

Configuring W3 total cache

In the general tab, enable the CDN for Amazon services, as shown below.

w3cdn

Then you need to enter your credentials in the CDN settings tab.

Fill in your Amazon Services keys, the name of the bucket, the name of the distribution and the name of the CNAME record.

settings

Before testing, be sure your distribution is deployed and your CNAME resolved. In my case, W3 total cache never could pass the test, I receive a “cannot resolve domain name” error. But the plugin was able nonetheless to upload data to the bucket.

Uploading your data

W3 Total cache suggests that you upload you WordPress files to your bucket. Do so for each suggested folder and media and voilà! You should have WordPress installation running on your CloudFront!

You can go further with this plugin and optimize your WP installation.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">