Why not just use a CDN, then?

Well, here’s the thing:

You still can use a CDN. It’s surprisingly simple to connect your Amazon S3 bucket to your favorite CDN. You can use it with everything from Cloudflare to KeyCDN to Stackpath.

Amazon Web Services even has their own CDN, called CloudFront, that’s also super easy to connect to Amazon S3.

In fact, that’s how I recommend you do it if you have a global audience.

By using both, you:

  • still get the storage benefits of S3
  • also get the performance benefits of a CDN

The WordPress S3 connection explained

If you follow the instructions in this post, here’s how your WordPress site is going to function at the end of this WordPress S3 tutorial:

  • You upload files to your WordPress Media Library like normal (i.e. through the regular Add Media button)
  • Your chosen WordPress S3 plugin automatically copies or moves those files to Amazon S3
  • Your WordPress site either serves the file that’s stored on S3 or uses a CDN that’s connected to your S3 bucket

Here’s what you need in order to set up the WordPress S3 integration

To connect WordPress to Amazon S3, you’ll need:

  • An Amazon Web Services account – this is free to sign up for.
  • A public Amazon S3 bucket – this is free for your first year (up to 5GB). I’ll show you how to create one.
  • A WordPress S3 plugin – this helps you automatically offload the files that you upload to WordPress to your S3 bucket.

Which WordPress S3 plugin should you use?

There are a few different WordPress S3 plugins that you can choose from:

  • WP Offload Media Lite – has a fairly generous free version, but that free version only works with newly uploaded files. If you go Pro, you’ll also be able to store and serve your assets from S3 and upload existing files. Also makes it very easy to use a CDN later on (if that’s in your plan).
  • W3 Total Cache – W3 Total Cache includes a feature that lets you connect your site to Amazon S3 if you choose S3 as your CDN in the W3 Total Cache settings.
  • Media Library Folders Pro S3 – lets you manage your WordPress media library with folders while simultaneously offloading all or some of those files to Amazon S3 and maintaining the same folder structure.
  • Human Made S3 Uploads – with no actual interface, this GitHub-hosted project from Human Made isn’t built for casual users. But developers should appreciate it. You can read more about it here.

The WordPress S3 plugin that I will use for this tutorial

For this tutorial, I’m going to use WP Offload Media Lite from Delicious Brains because it’s the most well-known option at the time that I’m writing this article.

But here’s the thing about the setup process:

Most of the steps will happen in the Amazon S3 interface and are identical across all plugins. That means you can probably follow most of this guide even if you decide to use one of the other plugins.

The only differences will be the very brief portions that happen inside each plugin’s interface.

How to use WordPress with Amazon S3: step-by-step

Here’s everything that you need to do to start using Amazon S3 with your WordPress site:

It should probably go without saying, but I highly recommend that you back up your site before you begin this process.

Step 1: Install and activate WP Offload Media Lite plugin

You’re not really going to do anything in the plugin’s interface quite yet. But before you jump into the Amazon S3 interface, it’s a good idea to make sure that you have the plugin installed and activated on your site.

When you activate WP Offload Media Lite, it will prompt you to Define your AWS keys.

Over the next few steps, you’ll follow the process to actually generate those keys.

Step 2: Create a new bucket at Amazon S3

If you haven’t already created a free Amazon Web Services account, go ahead and do that now.

Once you create your account, either navigate to the Amazon S3 section from inside your AWS account dashboard or click here to go straight to S3.

In the S3 interface, click the button to Create bucket:

amazon s3 interface

On the popup interface:

  • Give your bucket a name
  • Choose a Region (make this as close to your target audience as possible, especially if you’re not planning to use a CDN)
  • Click Create

create s3 bucket

Step 3: Set your bucket policy

In order for everything to function properly, you need to make your S3 bucket public. To do that, you use something called a bucket policy.

To add a bucket policy, click on your bucket in the S3 interface:

edit bucket

In the screenshot above, you can see that my other bucket is already public, while the codeinwp bucket that I created for this tutorial is marked as Not public. After this step, you want that Public indicator for your bucket as well.

On the next screen, click on the Permissions tab and then select Bucket Policy:



Source link