If you’ve been using WordPress for any number of years chances are your uploads folder within wp-content is pretty huge. I’ve been running BestTechie on WordPress since 2006, that’s nearly 12 years at this point and my uploads folder which holds all of the images and other media files for my posts is currently sitting at over 4GB in size with more than 66,000 media files in it. The thing about the uploads folder is that it’s constantly growing in size. This can add additional expenses to your server(s) and backups. There’s also a better way to handle all of these media files for your WordPress site.
The fine folks at DigitalOcean (who I use to host BestTechie) have recently released a new product called DigitalOcean Spaces which is very similar to Amazon’s S3. Essentially, Spaces are designed to make it easy and cost effective to store and serve massive amounts of data. You can create them in a few seconds and use them immediately with no configuration. Data transfer is automatically secured with HTTPS, and the available storage capacity scales seamlessly. The company is currently offering a free 60 day trial for customers and after that Spaces cost just $5/month and come standard with 250GB of storage and 1TB of outbound transfer. Additional storage will run you $0.02/GB and additional outbound transfer from Spaces to the Internet costs $0.01/GB. It is recommended that your Space is in the same datacenter as your web server. Both my web server and Space are in NYC3.
Once you have gone ahead and created your brand new Space, you need to generate an API access key, you can do that in the DigitalOcean dashboard under Spaces access keys. Click Generate New Key and be sure to copy and save the key as well as the secret key. You will need both! Now that you have the Space setup and your access keys, this is how you go about setting up WordPress to start using it.
I wanted to be able to smoothly transition from hosting all my media files on my web server to hosting them in the cloud (via DigitalOcean Spaces). The following steps would allow me to eventually (when I’m ready) remove the media files from my web server and keep everything stored in the cloud.
The first thing I did was download the uploads folder my server to my computer. The next thing I did was install a tool called rclone on my Mac (the installation instructions can be found at that link). Once rclone is installed, you need to configure it to work with your new DigitalOcean Space.
The configuration on the rclone page which I linked above is almost perfect. The one change I made was when it asks for “acl” I typed in public-read. This will make all of the media files you’re about to upload to your new Space viewable on the internet (which you want).
When rclone is configured, the config file should look like this:
type = s3
env_auth = false
access_key_id = YOUR ACCESS KEY ID
secret_access_key = YOUR SECRET ACCESS KEY
endpoint = the_datacenter_you_chose.digitaloceanspaces.com (e.g. mine is nyc3.digitaloceanspaces.com)
acl = public-read
Now in the terminal go to where you have your uploads folder located on your computer. For example, mine was in my Downloads folder so I typed:
Next I executed the following rclone command:
rclone copy uploads/ spaces:the_name_of_your_space
Obviously your command will need to be slightly different. My DigitalOcean Space is named btfiles so that’s what I put after spaces:, you will need to put whatever it is you call your Space. After you type out that command, hit enter and rclone should start copying all of the files in your uploads folder on your computer to your brand new DigitalOcean Space. Note: this may take some time, it could take several minutes to potentially more than an hour depending on your internet speed and how many files you have–just let it do it’s thing.
After all the media files have been placed in the cloud storage, the next thing you need to do is to install the Media Cloud plugin for WordPress. The plugin will allow you to automatically upload all new images to your Spaces storage. It can even be configured to delete the files from your web server after they are synced to your cloud storage, therefore saving you space on your web server.
In Media Cloud’s storage settings section, you’ll want to configure it like this:
Obviously replace the btfiles bucket name with your own Spaces name and make sure to adjust the custom endpoint URL to whatever datacenter you selected when you created your Space. The rest of the settings on the page should be fine with the defaults, at least to get you started. You can tinker with whether or not you want to delete stuff on your web server later. For now, you just want to get everything working properly.
And lastly, you’ll need to adjust the Full URL path to files setting in WordPress under the Settings -> Media section. In that field you will want to enter the URL of your Space which should be something like: https://space_name.datacenter.digitaloceanspaces.com (e.g. https://btfiles.nyc3.digitaloceanspaces.com)
That should do it. Now all of your old media files are located on your brand new cloud storage and all newly uploaded media files in WordPress will automatically sync there as well. Have any questions, comments, tips? Let me know in the comments!