How to Migrate Your WordPress Media Library to Amazon S3 on the CHEAP!

One thing has irked me over the years is the near monopoly that Delicious Brains holds on the WordPress-to-S3 market AND their corresponding price-gouging and strange pricing for their S3 plugin. Just yesterday, for example, I received an “paid upgrade required” notice in the middle of an upload! Here’s how to break their monopoly and migrate your WordPress media library to S3 on the cheap.

Step 1: Upload your media library to Amazon S3.

There are lots of ways to do this. If you have access to WP-CLI, then you might try Humanmade’s S3 Upload plugin. Otherwise, you can use Cyberduck or Amazon S3’s native gui web console. UPDATE: I’ve been having great luck migrating the WordPress media library to S3 with the $3.99/mo version of MediaCloud’s S3 plugin (go ahead and cancel your monthly Media Cloud plan after migrating! e.g. You’re out a meager $3.99 rather than hundreds that you’d pay Delicious Brains for the same service).

If you haven’t already, make a full site backup, as the steps below will change both your file structure and your database.

Assuming you’ve purchased MediaCloud’s plugin @ $3.99/mo (remember, you can cancel tomorrow!), go to the “Media Cloud”->”Settings” menu and add “wp-content/uploads/” to the upload path as follows:

This is the Media Cloud plugins path setting for DURING the S3 upload process
This is the Media Cloud S3 plugin’s “Upload Path” setting for DURING migration to S3.

(Technically, the above step is optional, however, I like to use it, since it’s the default WP structure.)

Then go to “Media Cloud”->”Migrate to Cloud” and select the following options:

media cloud s3 settings for bulk uploading migrate to cloud
media cloud s3 settings for bulk uploading migrate to cloud

Then go ahead and click “Start Migrate to Storage”.

Step 2: Either Search and Replace Media URLs in your database and theme OR Update .htaccess OR use Redirection WP plugin

NOTE: If you used the paid version ($3.99) of the Media Cloud plugin to upload your files, the media files’ urls have already been rewritten, however, any references to the files in the theme or plugins (Yoast, Email log, Redirection, Divi, Beaver Builder, etc.) will need to be updated – so make sure you still do a search-and-replace for the urls.

OPTION 1: Search & Replace the database

If you are on an NGINX server or don’t have access to edit your .htaccess file, you’ll (unfortunately) need to run a search-and-replace on your WordPress database. If this is the case for you, use the free version of Better Search and Replace plugin (by Delicious Brains – teehee!) to replace instances of “your_website.org/wp-content/uploads” with “your_bucket.s3.us-east-2.amazonaws.com/wp-content/uploads” as follows:

wordpress to amazon s3 search and replace
How to Migrate Your WordPress Media Library to Amazon S3 on the CHEAP! 8

NOTE: Even if you use Option 1, I still recommend doing Option 3, as some themes and plugins use a “relative url” rather than “your_website.com…” (I’m looking at you, Divi!!!).


OPTION 2: .htaccess update

If you DO have access to your .htaccess file, then the solution is much simpler – just add this after the “RewriteEngine On” line:

# BEGIN Utilize S3 bucket rather than localhost for "uploads" folder - Via https://tinyurl.com/s3redirect
RewriteRule ^wp-content/uploads/(.*)$ https://bucket_name.s3.amazonaws.com/wp-content/uploads/$1 [R,L]
# END Utilize S3 bucket

OPTION 3: Redirection Plugin

If you decide to use the free Redirection plugin do the following (also see example screengrab below):

Source url: /wp-content/uploads/(.*)$
Target url: https://your_bucket_url.s3.us-east-2.amazonaws.com/wp-content/uploads/$1
Type: Regex
redirection plugin setup for Amazon S3
This is the Redirection WordPress Plugin’s setup for S3-enabled sites.

Step 3: Install and Activate the Free WP Offload Media Lite WordPress Plugin OR deactivate the Media Cloud license.

Either install and activate the free WP Offload Media Lite plugin and configure it to connect to your bucket OR deactivate your Media Cloud license if you used that plugin to upload to S3. If you are using the Media Cloud plugin, update your “Upload Path” and “Delete…” settings as described in the screengrabs below:

This is the Media Cloud plugins path setting for AFTER the S3 upload process
This is the Media Cloud S3 plugin’s “Upload Path” setting for AFTER migration to S3.
media cloud s3 delete settings
Change your “delete” settings within the Media Cloud S3 plugin.

That’s it – you’re done! Go ahead and rename your “uploads” folder to test it out; if all looks good, delete your local “uploads” folder!

Recap

To recap, completing the above steps accomplishes the following:

  1. Your media library is now on S3.
  2. Your media urls now reference only S3.
  3. New media uploads will be uploaded and loaded from S3.

Notes

delicious brains offload to s3 error
Here’s an error message I received from the paid version of Delicious Brains’ S3 plugin (Agh! The pain!). Fwiw, 20,000 media uploads isn’t actually that many uploads. In fact, every single image you upload to WordPress might create 5-10 additional “attachments” of that image (e.g. 1 upload = 11 attachments); the WordPress default is 3 additional attachments for every 1 image you upload.
  • This post turned into an accidental advertisement for Media Cloud, but I assure you that I’m not affiliated with them, nor am I accepting anything from them for this post. I just found their plugin to be wonderful and CHEAP!

Toby Cryns

RSS From Toby’s Blog

  • How Digital Ocean Cost Us Thousands of Dollars in a Single Day
    Here’s the rub for me: My belief is that bad stuff happens, and you need to own it. Digital Ocean definitely did not own it in this case. I wonder how the original founders of Digital Ocean would have reacted had they been in charge… For example, wouldn’t it be nice if an actual human… […]
  • Where uncertainty exists, don’t order specific.
    4 Idiot Case Studies with 2 simple age-old business lessons. The post Where uncertainty exists, don’t order specific. appeared first on Toby Cryns, WordPress Trainer in Minneapolis, MN.
  • “Now THAT was a good meeting!”
    A single effective meeting can change the course of history for a company. Imagine if you could lead effective meetings EVERY DAY! You can, but it takes curiosity & practice. This article is a good place to start your journey to a more effective you. The post “Now THAT was a good meeting!” appeared first […]

More posts from themightymo.com

How to merge multiple csv files via command line

How to merge multiple .csv files via command line

By The Mighty Mo! Design Co. | May 17, 2023

Today I downloaded 29 csv files with tax information. I could import those files 1 at a time into WooCommerce, but wouldn’t it be nice if I could merge them first and then only import a single file? The unix command is simple – just navigate to the folder with all the csv files and…

WordPress Security Services

15 Best WordPress Support and Maintenance Services for 2023: Ensuring Your Website Stays in Top Shape

By The Mighty Mo! Design Co. | April 27, 2023

Small business owners and non-profit leaders know that keeping your website secure, fast, and fully-functional is critical to success.  Here’s the unspoken truth: You can either learn how to do all that tech maintenance and development stuff yourself, or hire someone else to do it. But let’s face it, doing it yourself isn’t always the…

how to set up Cloudflare whitelist for ip

How to Whitelist SEM Rush IPs in Cloudflare

By The Mighty Mo! Design Co. | April 24, 2023

Alright, I’m going to show you how to whitelist a set of IPs on CloudFlare. In our case we use SEMrush and we want to make sure the SEMrush has full access to our sites.

RSS From Toby’s Blog

  • How Digital Ocean Cost Us Thousands of Dollars in a Single Day
    Here’s the rub for me: My belief is that bad stuff happens, and you need to own it. Digital Ocean definitely did not own it in this case. I wonder how the original founders of Digital Ocean would have reacted had they been in charge… For example, wouldn’t it be nice if an actual human… […]
  • Where uncertainty exists, don’t order specific.
    4 Idiot Case Studies with 2 simple age-old business lessons. The post Where uncertainty exists, don’t order specific. appeared first on Toby Cryns, WordPress Trainer in Minneapolis, MN.
  • “Now THAT was a good meeting!”
    A single effective meeting can change the course of history for a company. Imagine if you could lead effective meetings EVERY DAY! You can, but it takes curiosity & practice. This article is a good place to start your journey to a more effective you. The post “Now THAT was a good meeting!” appeared first […]