Using Amazon S3 for images and media on your WordPress Site
I currently use WordPress for nearly every site I mange, which is nearly 100 sites Recently, I started creating sites with many more images than my previous sites. I wanted to find a quick and easy way to host these images on Amazon S3 services without having to change how I use WordPress. Fortunately, I found a plugin that is easy to install and configure, and works every time I want to use it.
What is Amazon S3
Amazon S3, short for Simple Storage Solution, provides storage space for any amount of data which can be accessed any time of day from anywhere on the web. It gives any developer access to the same highly scalable, reliable 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.
For web sites, this means you can place your images, videos, and other data files into a large network designed to deliver the files quickly, and scale to fit your needs. The low cost and zero startup fees make Amazon S3 a great benefit to new web sites, and the scalability keeps pace with growing demands.
Step One: The WordPress Site
The first thing we are going to need of course is a WordPress site. I will not go into a whole lot of detail here as there are many great tutorials available for installation and setup of a WordPress site. Most hosting providers will offer simple installation of WordPress on your account.
Please Note: This will not work with sites hosted on WordPress.com. You must use self-hosted WordPress to use Amazon S3 for your images.
Step Two: Amazon S3 Signup
Now that you have your WordPress site up, before you upload any images, you will want to get your Amazon S3 account. You will need to sign up for a free Amazon Web Services (AWS) Account to get access to the tools you need. Once you have an account, or log in to your account, you need to Sign Up for Amazon S3. You will need to enter a credit card here so when you owe money Amazon can charge you, but don't worry - you will not be charged anything right now.
Soon after you sign up for Amazon S3 you will receive instructions on how to access the management console for the service. This is where you will set up a "bucket" to hold the images for your site.
Step Three: The Bucket
Once you log in to the Management Console, you will see a list of Buckets. If this is your first time logging in, there will be no buckets. Click on the "Create Bucket" button or link to create the bucket for your site.
We are going to use domain masking for the images, so you will need to name the bucket properly. If your web site is example.com, and you want your images to load from images.example.com, then you would name the bucket "images.example.com". Of course, replace the domain name with your own. We will set up the DNS for this in the next step.
For new Amazon S3 users I do not recommend setting up any logging. Just click the "Create" button and your bucket will be created. For now, we can leave the AWS Management Console.
Step Four: Setting up DNS
Since we are going to be using Domain Masking for our images, we need to set up the DNS to direct calls to images.example.com to our bucket on Amazon S3. You will need to check with your hosting provider to get instructions on how to create a cname record. Often, you just need to provide them with the details, but many providers will have an option in your web site control panel to create these records.
For our example, images.example.com, we need to create a cname record that points to images.example.com.s3.amazonaws.com. This is where Amazon S3 shines with Domain Masking. If you create buckets with a fully qualified domain name, you can access the files and data by adding s3.amazonaws.com to the domain name. If you set up the DNS properly, you can access files with http://images.example.com/filename.
Step Five: The WordPress Plugin
Now comes what may be the easiest part of this configuration, the WordPress plugin. For this we will be using the plugin Amazon S3 for WordPress by Joe Tan. You can easily install this plugin by going to your sites dashboard, then under the Plugins menu click on "Add New". Search for Amazon S3 for WordPress and install the latest version, but make sure what you install is the one by Joe Tan.
After installing, you should activate the plugin. This plugin is WordPress network capable, so if you plan to use it on a network of sites, you can Network Activate it now. The plugin will not do anything until you configure the plugin for each site in the next step.
Step Six: Authenticating with Amazon
With all of the above steps completed, it is time to configure the plugin. You will need information from your Amazon account for this step. The information you need will be found on the Security Credentials page of your Amazon Account. You may need to sign in again, but don't worry, it's just an extra security step that protects this information.
Back in your WordPress dashboard under your Settings menu you will find an option for "Amazon S3". The first time you load this options page, you will be prompted for your AWS Access Key ID and your Secret Key. There is a link on this page to get your credentials. Copy both into the two fields then press the "Authenticate Account" button.
Step Seven: Setting up the Plugin
If you entered the correct data and the plugin was able to authenticate with Amazon S3, you should see a section called "Amazon S3 Settings" on the resulting page. For security purposes your Secret Key will not be shown here (in the image I hid my Access Key ID, but yours should show here).
Below these two fields there will be a drop down box that contains the buckets in your Amazon S3 account. Select the bucket we created above. This is where the plugin will copy all of your media files so they can be accessed when your site is viewed.
There are four check-boxes below where you select your bucket. For this to work with Domain Mapping, you will need to check all four of the boxes.
- Host name Settings: Since we are using domain masking, and we set that up above, we will want to check this box.
- File Uploads: Checking this box will automatically copy all media uploaded through WordPress to your bucket.
- Expires Header: Check this - it will save you a lot of bandwidth and money. It just means that your images and other files will be cached and not downloaded every time someone visits your site.
- File Permissions: CHECK THIS. If you don't, your images will show to you but may not show to other people.
Oh, and don't forget to Save your settings.
We are done!
That's it. Once you have completed all seven steps above, your site is set up to use Amazon S3 for hosting images. Every time you upload an image through any of the tools in WordPress, the plugin will automatically copy all of the generated sizes to your bucket. The files will be stored in the same structure as they would be on your local server.
Test it out. Go to your media menu and upload something. When you are done, check your Amazon S3 Management Console to see it there. Then double click on the item in your bucket to view it. If everything is set up correctly, the plugin will automatically use your bucket name in the URL of your image.
Some Caveats
I wanted to close with a few bits of information you should know about. First, all of the files you upload through WordPress will also be stored locally on your machine. This allows you to switch back to local hosting if you feel that you are Amazon S3 costs more than it is worth. Because of this, you will want to make sure you have plenty of space on your hosting server for all of your media files.
Second, when you delete a file from WordPress, the plugin does not remove it from S3. If you delete an image, then upload the same file again, any files on S3 will be overwritten with the new files. Usually this is not a problem, but you should be aware of this behavior.
Finally, any images uploaded to your site before you activate the plugin will continue to be served from your server. I am currently unaware of any option to force older posts and pages to use images from Amazon S3 without manually editing each one.
Comments
All images uploaded using the WordPress upload tools will be stored on your server. With the plugin used for this article is installed and set up correctly, those files will also be copied to Amazon S3, but will also be located on the local server as well.


John cox 12 months ago
This is a great article and still working my way through it - really explains the structure and reasons and I have booked marked it as well - a BIG thanks.
Can you also explain in the closing remarks you say "I wanted to close with a few bits of information you should know about. First, all of the files you upload through WordPress will also be stored locally on your machine. This allows you to switch back to local hosting if you feel that you are Amazon S3 costs more than it is worth. Because of this, you will want to make sure you have plenty of space on your hosting server for all of your media files"
Can you explain here - do you mean all files uploaded using the wordpress upload "old way" will still be on your hosting account and ones added through the s3 pluggin will reside on the amazon server ...thanks ..