How to Setup a CDN with CloudFront

Want to know how to install a CDN with CloudFront?  I did too, and after searching for days I couldn’t find one good tutorial that walked through the entire process.  After a day or two of troubleshooting I was able to get a CDN working on my site with WP Super Cache.  I use Amazon Web Services and in particular, their CloudFront and S3 service.  You may have been notified by ySlow or some other web tool, that having a CDN helps boost speeds.  This is true.  It does so by hosting your site’s files on multiple servers across the entire globe.  This allows people overseas to be closer to the “server”, and thus, shorten the time it takes to load a page.  If you host a server in the United States, than you might not see much of a difference because you were already near the server.  I saw a slight speed boost, mostly because my server is severely underpowered as it is.  At this point, hosting my content on a different server saves requests, bandwidth, and time.

And now for the step-by-step tutorial on how to setup a CDN with CloudFront using WP Super Cache in WordPress. We will be using an Original Pull method.

  1. Go to Amazon Web Services (AWS) and sign up.
  2. At the top of the screen, click the link, “Sign in to the AWS Management Console.”
    Screen shot 2011 07 29 at 10.34.35 AM How to Setup a CDN with CloudFront
  3. In the secondary horizontal navigation, click on the CloudFront Tab seen below…
    Screen shot 2011 07 29 at 10.39.33 AM How to Setup a CDN with CloudFront
  4. The yellow box below asks you to sign up for CloudFront.  Click the yellow-orange button located on the left-hand side, below this yellow dialogue box.
    Screen shot 2011 07 29 at 10.43.34 AM How to Setup a CDN with CloudFront
  5. Follow the next couple steps and fill out all the information necessary.  AWS will call you to confirm identity.  This will be an automated massage so you won’t have to talk to a real person.  Just enter the code they provide you.
  6. SPECIAL NOTE :: You will not have to pay a single cent until you have correctly setup CloudFront.  You only pay for the live data you exchange.  See the pricing section for more info.
  7. Log back into the AWS Management Console.  You may already be in this screen.
  8. Make sure you have clicked on the S3 Tab located in the second horizontal navigation.  (This should be the default screen for the management console.)
    Screen shot 2011 07 29 at 10.53.12 AM How to Setup a CDN with CloudFront
  9. Under the “Buckets” header, click on the “Create Bucket” button.
  10. Usually a good name for a bucket is, “cdn.yourSiteName”.  This keeps things simple with a clean name.  Finish creating this bucket and confirm.
  11. Click on the CloudFront tab located in the secondary navigation.
  12. Below this navigation on the far left is a button entitled, “Create Distribution.”  Click on this button.
    Screen shot 2011 07 29 at 11.01.03 AM How to Setup a CDN with CloudFront
  13. This will prompt you with a new dialogue box, “Create Distribution Wizard.”  First, select the “Download” radio button under the section, “Delivery Method.”
    Screen shot 2011 07 29 at 11.04.56 AM How to Setup a CDN with CloudFront
  14. In the “Select Bucket” option, find the S3 bucket you created in step 10 and click “Continue”.
  15. In the second step of the Wizard you will leave most options to the defaults or empty.  First, for the options that displays, “Default Root Object”, type in, “index.php” .   Make sure this is all lowercase and no http:// or www. suffixes.
  16. Next turn “Logging” ON.
  17. For “Select Log Bucket” find your S3 bucket in the drop-down.
  18. Finally, make sure “Distribution Status” is set to “Enabled”, click “Continue”, and “Create Distribution”.
  19. You have now successfully setup CloudFront for WP Super Cache.

Setting Up WP Super Cache

  1. First follow my guide on setting up WP Super Cache.
  2. In the wp-admin screen, go to Settings > WP Super Cache > CDN tab.
    Screen shot 2011 07 29 at 1.01.17 PM How to Setup a CDN with CloudFront
  3. Most of the settings will remain at the defaults. First, check the box adjacent to “Enable CDN Support”.
  4. Next to “Off-site URL” type in “http://yourS3BucketName.com”. For Example, mine is http://cdn.geebart.com.  You created the name for this bucket in steps 9-11, in the last section.
  5. Scroll to the bottom and click the large blue button, “Save Changes”.
  6. Now we must clear the old cache.  Go to the “Contents” tab, scroll to the bottom of this page, and click on the large gray button, “Delete Cache”.  This will reset WP Super Cache to correctly display new content from the new CDN.
    Screen shot 2011 07 29 at 1.15.24 PM How to Setup a CDN with CloudFront
  7. Click the “Preload”, scroll to the bottom of this page, and click the large gray button, “Preload Cache Now”.  This will now generate new cached files with CDN support.
  8. Go to your website in a browser.  Right click on the static background of the site and select, “View Page Source”.
    Screen shot 2011 07 29 at 1.16.27 PM How to Setup a CDN with CloudFront
  9. Find a URL/blue link that contains “http://yourCDN.com.  Click on one of these links to make sure the contents/media are loading properly.  If successful, than you have successfully implemented Amazon CloudFront CDN with WP Super Cache.

Troubleshooting

When I first installed this CDN, I did notice some errors in the wp-admin screen. Initially, I could login, but I couldn’t click on any links. I would receive database errors. Just remember to clear the cache and be patient for the entire site to cache properly. You also may need to clear the cache on WP Minify if you are using it.

For more info on troubleshooting, check out these links…

AWS Support
Other Tutorial

Feel free to leave questions in the comments sections below.

Posted in Blog, Tutorial, WordPress | Tagged , , , , , | 6 Comments

6 Responses to How to Setup a CDN with CloudFront

  1. Pingback: Geebart

  2. Jerry Johnson says:

    Wow. Great writeup. This step-by-step lesson is exactly how I learn best. Thank you.

    (Of course, there goes part of my weekend as I see if your other posts hit me as solidly.)

  3. There’s a poll over on CSS tricks about using a CDN vs a local file and one of the comments is that you can “fallback” on a local file when your CDN file is not available.

    http://css-tricks.com/13261-large-file-on-cdn-or-small-local/#comment-99474

  4. Excellent write up man!!

    I’m planning on implementing a CDN for a client, and was a little short on the best way to implement it, but your write up definitely delivers the point.

    My client is going to be happy. Thanks dude!

  5. Thank you so much! I have been searching for a step by step guide to set my site up with Amazon’s CDN and there are not many / any really good ones. Your’s is just what I needed. Thanks again!

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 class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

Like this post?

Subscribe to the RSS Feed or to Email Updates, right now!