Wpdaily

Daily WordPress News

How to Offload WordPress Media to S3: 2 Ways (One Is

Want to offload WordPress media to S3 but not sure where to get started? This post will show you exactly how to set it up using two different methods.

One method literally just takes a few clicks, while the other method is a little more involved but gives you more options for customization.

Offloading your WordPress site’s media to Amazon S3 has a lot of benefits. Most notably:

  1. You can reduce storage usage at your host, which lets you save money.
  2. Your media is portable, which means you can really easily migrate your site to new hosting without downloading/reuploading everything.
  3. It lessens the load on your server, which helps it perform better under scale.

Of course, if you’re reading a guide on how to offload WordPress media to S3, you’re probably already convinced of the benefits.

For that reason, I’m not going to waste time explaining the “why” in detail. Instead, I’m going to jump straight into sharing two step-by-step tutorials for how to offload WordPress media to S3.

Explaining the two different ways to offload WordPress media to S3

In the tutorials below, I’m going to show you how to use two tools:

  1. Optimole – the simple option
  2. WP Offload Media – the technical option

Introducing Optimole – the simple option

Optimole offers the easiest way to offload WordPress media to S3

Optimole is a full-service image optimization solution for WordPress sites that offers real-time processing and optimization.

It can handle every part of optimizing your site’s images, including the following:

  • Serving adaptive images that are being optimized for each user’s device in real-time.
  • Compressing images in an optimal way for each device.
  • Resizing images to the best dimensions for each device.
  • Converting images to the optimal format, with support for WebP and Avif.
  • Serving images via its built-in Amazon CloudFront CDN.

If you want to offload your images to S3, Optimole also offers a one-click option that lets you do that.

When enabled, images will be moved off your server and onto S3. Optimole will also still serve them via Amazon CloudFront, which offers better performance than serving from S3 directly.

If you ever want to restore the offloaded images to your server, you can also do that with one click.

The main advantage of Optimole is its simplicity. You literally just need to enable one toggle and click a button to fully offload your images – you won’t find a simpler way to offload WordPress media to S3.

 There are two things that you’ll want to consider, though:

  1. Optimole is mainly focused on offloading images. While it does offer a feature to handle short GIFs (including converting GIFs to MP4 and WebM), Optimole is not the best option if you want to offload long-form videos (e.g. video content for your online course).
  2. You don’t control your own S3 bucket. Optimole is able to make the process so simple because it eliminates the need to create your own S3 bucket and sync it to WordPress. However, if you do want to actually have your own S3 bucket, you also might want to consider the other tool.

Optimole is free for up to 5,000 monthly visits on your site(s). After that, paid plans start at $19 per month for 50,000 visits.

Introducing WP Offload Media – the technical option

WP Offload Media offers a more technical way to offload WordPress media to S3

WP Offload Media is a freemium WordPress plugin that lets you offload all of your WordPress media to S3, with additional support for DigitalOcean Spaces and Google Cloud Storage.

You’ll create your own S3 bucket via the AWS console and then connect it to WordPress by creating an AWS user.

If you want to serve your media via a CDN, you’ll also need to set up your own CDN integration as it’s not built-in like Optimole.

Those are the main disadvantages – it’s not nearly as simple to set up and you’re responsible for configuring everything.

 However, this approach also has some potential advantages:

  1. It works for any type of media, including images, videos, documents, and so on.
  2. You control your own S3 bucket, which might be important if you’re a developer who wants to make your own customizations.

WP Offload Media has a limited free version. However, one huge limitation is that the free version only lets you offload new files – it doesn’t let you do that with your existing media. The free version also doesn’t let you remove the files from your server after offloading them.

If you want to fix those limitations (plus get other enhancements), the paid version starts at $39 for up to 2,000 offloaded media items and goes up to $199 for 40,000 offloaded media items.

How to offload WordPress media to S3 with Optimole

Optimole offers the absolute simplest way to offload WordPress media to S3. It literally takes just a few clicks.

Let’s go through it…

  1. Install Optimole and connect API Key
  2. Offload WordPress images to S3
  3. Configure other Optimole image optimization settings

1. Install Optimole and connect API Key

To get started, install the free Optimole plugin from WordPress.org.

When you activate the plugin, Optimole should prompt you to register for a free API key (or provide your existing API key if you already have a free Optimole account).

If you don’t see this screen automatically, you can access it by going to Media → Optimole.

If this is your first time using Optimole, enter your email address and click Create & connect account.

Sign up for API

Optimole will now work on setting up your site automatically – it should only take 30 seconds or so.

Once that’s done, you’ll see a success message:

Optimole dashboard

You’re almost finished!

2. Offload WordPress images to S3

To offload WordPress images to S3, follow these instructions:

  1. Go to the Settings tab in Optimole (in your WordPress dashboard).
  2. Click the Cloud Integration tab in the sidebar.
  3. Enable the Enable offloading images toggle.
  4. Click Save changes.
How to offload WordPress media to S3 in Optimole settings

Optimole will now automatically offload all new images that you upload.

If you want to also offload the existing images in your Media Library, you can click the Sync images button (you need to save your changes before this button appears).

Enable the offload WordPress media to S3 option for existing images

That’s it!

If you ever want to restore the offloaded images to your WordPress site’s server, all you need to do is click the Rollback images button and Optimole will restore all of the images for you.

3. Configure other Optimole image optimization settings

At this point, you’ve successfully offloaded your images to S3.

However, as I mentioned above, Optimole also offers lots of other features to help serve your WordPress images in an optimal way.

While a lot of these optimizations happen automatically, you can explore the Advanced settings area to customize your preferences for details like image compression, image resizing (including an option for smart cropping), lazy loading, and more.

Other Optimole settings

How to offload WordPress media to S3 with WP Offload Media

To set up WP Offload Media, the process is a little more technical and will require more time than Optimole. Again, this is the tradeoff that you make in exchange for having control over your own S3 bucket.

Here’s a quick summary of the steps – keep reading for a more detailed breakdown of how it works:

  1. Create an IAM user in AWS.
  2. Attach the proper access policy for the IAM user.
  3. Create a programmatic access key for your user.
  4. Add your access keys to the plugin’s settings.
  5. Create a new S3 bucket for your WordPress site (you can do this right from the plugin’s settings).
  6. Configure the plugin to offload media to S3.
  7. Set up a CDN to serve your media (optional).

For this tutorial, we’re using the free version of the plugin, but the basic steps are the same for the paid version.

1. Create a new IAM user in AWS

To start, log in to your existing AWS account, or create a new one if you don’t have it yet.

Once you’re logged in, click this link to open the IAM users dashboard and then click the Add users button:

Add a user in AWS

On the next screen:

  1. Give your user a unique name to help you remember it – e.g. [site-name]-wp-offload-media.
  2. Click Next.
User details

2. Attach proper policy to IAM user

Now, you need to attach a permission policy to this user so that it’s able to access S3:

  1. Choose the option for Attach policies directly, which should display a Permissions policies search below.
  2. Search for s3full in the Permissions policies box.
  3. Check the box next to AmazonS3FullAccess (which should be the only policy that your search returned).
  4. Click Next.
Attach policy to user

On the next screen, verify that the information is correct and then click the Create user button.

Create the AWS user

3. Create an access key for your user

Now, go back to the main IAM users list and select the user that you’ve just created.

Create an access key

Next up:

  1. Go to the Security credentials tab in the user’s settings.
  2. Scroll down to the Access keys box.
  3. Click the Create access key button.
Open security credentials

On the next screen, choose the Application running outside AWS option and then click Next.

Select access key type

Then, add a description – e.g. WP Offload Media – and click Create access key.

Create your AWS access key

AWS will now show you two pieces of information:

  1. Access key
  2. Secret access key
AWS access keys to offload WordPress media to S3

Copy both of them to a safe spot because you’ll need them in a second and AWS will not show them to you again after you leave this page.

Don’t worry, though – if you do accidentally lose your access key, you can just repeat these steps to create a new one.

Once you’ve copied them to a safe place, click Done.

4. Add access keys to WP Offload Media settings

Now, open your WordPress dashboard.

If you haven’t already installed and activated the WP Offload Media plugin yet, you’ll want to do that now.

Then, go to Settings → WP Offload Media.

Choose Amazon S3 as your provider.

Then, choose your Connection Method.

I recommend adding the access keys to your site’s wp-config.php file using the code snippet that the plugin provides. However, if you’re okay with a less secure method, you can also choose the I understand the risks… option to add your access keys to the plugin’s settings (which will save them in your database).

Choose connection method

Here’s how to add the access keys to your wp-config.php file:

  1. Take a backup of your site just in case anything goes wrong.
  2. Connect to your server using FTP or something like cPanel File Manager.
  3. Edit the wp-config.php file.
  4. Add the following code snippet near the top of the file, making sure to replace the asterisks with your actual access key and secret access key.
define( 'AS3CF_SETTINGS', serialize( array(
	'provider' => 'aws',
	'access-key-id' => '********************',
	'secret-access-key' => '**************************************',
) ) );

Here’s what it might look like:

Add AWS access key to wp-config.php

Once you’ve saved the wp-config.php file (and reuploaded it if needed), click the Save & Continue button in the plugin’s settings. It also might automatically detect the change and reload the page without requiring you to click anything.

5. Create an S3 bucket for your site (or select an existing one)

Now, you’ll see an option to select an existing bucket from your AWS account or have the plugin create one for you.

For this tutorial, I’ll choose the Create New Bucket option, but you’re free to choose an existing bucket if you’ve already created one.

Create a new S3 bucket to offload WordPress media to S3

Then, click the Create New Bucket button.

6. Configure how to offload WordPress media to S3

Now, you’ll see a bunch of settings that let you control how to offload media.

The defaults should be fine for the most part, but you’ll want to pay special attention to two settings:

  1. Offload Media – make sure this is enabled.
  2. Remove Local Media – enable this if you want to delete the local version of your media after it’s been offloaded. If you leave it disabled, the file will exist on both your site’s server and the S3 bucket.
Offload your media

7. Set up a content delivery network (CDN)

Unlike Optimole, using WP Offload Media does not automatically serve your media via a CDN. Instead, your media will be served directly from the S3 bucket, which isn’t optimal for performance.

If you’d like to use a content delivery network, the plugin does include a feature to let you rewrite your media URLs to serve from the CDN instead of the S3 bucket.

You can do this from the Delivery Settings tab. Click the Edit button next to Delivery Settings to view the option.

Configure a CDN for your offloaded media

However, setting up a CDN is outside the scope of this article. If serving your S3 media from a CDN is important to you, you can consult WP Offload Media’s documentation or use Optimole for a simpler CDN setup.

Offload your WordPress media to S3 today

There you have it – two different methods to offload WordPress media to S3.

Both methods get the job done, but they go about it in different ways.

If you want the simplest way to achieve the benefits of offloading your images, Optimole is probably the best option because the setup is quick and painless.

On the other hand, if it’s important to you to have access to your own S3 bucket (or if you primarily want to offload long-form videos), WP Offload Media might be a better option.

Do you still have any questions about how to offload WordPress media to S3? Let us know in the comments.

Source