Tutorial

How To Store WordPress Assets on DigitalOcean Spaces

How To Store WordPress Assets on DigitalOcean Spaces

Introduction

DigitalOcean Spaces is an object storage service that can be used to store large amounts of diverse, unstructured data. WordPress sites, which often include image and video assets, can be good candidates for object storage solutions. Using object storage for these types of static resources can optimize site performance by freeing up space and resources on your servers. For more information about object storage and WordPress check out our tutorial on How To Back Up a WordPress Site to Spaces.

In this tutorial, we will use a WordPress plugin that works directly with DigitalOcean Spaces to use it as the primary asset store. The DigitalOcean Spaces Sync plugin routes the data of our WordPress media library to Spaces and provides you with various configuration options based on your needs, streamlining the process of using object storage with your WordPress instance.

Prerequisites

This tutorial assumes that you have a WordPress instance on a server as well as a DigitalOcean Space. If you do not have this setup, you can complete the following:

With these prerequisites in place, we’re ready to begin using this plugin.

Modifying WordPress Permissions

Throughout this tutorial, we will be working with the wp-content/uploads folder in our WordPress project, so it is important that this folder exists and has the correct permissions. You can create it with the mkdir command using the -p flag to create the folder if it doesn’t exist, and avoid throwing an error if it does:

  1. sudo mkdir -p /var/www/html/wp-content/uploads

You can now set permissions on the folder. First, set the ownership to your user (we will use sammy here, but be sure to use your non-root sudo user), and group ownership to the www-data group:

  1. sudo chown -R sammy:www-data /var/www/html/wp-content/uploads

Next, establish the permissions that will give the web server write access to this folder:

  1. sudo chmod -R g+w /var/www/html/wp-content/uploads

We will now be able to use our plugins to create a store in object storage for the assets in the wp-content/uploads folder and to engage with our assets from the WordPress interface.

Installing DigitalOcean Spaces Sync

The first step in using DigitalOcean Spaces Sync will be to install it in our WordPress folder. We can navigate to the plugin folder within our WordPress directory:

  1. cd /var/www/html/wp-content/plugins

From here, we can install DigitalOcean Spaces Sync using the wp command:

  1. wp plugin install do-spaces-sync

To activate the plugin, we can run:

  1. wp plugin activate do-spaces-sync

From here, we can navigate to the Plugins tab on the left-hand side of our WordPress administrative dashboard:

WordPress Plugin Tab

We should see DigitalOcean Spaces Sync in our list of activated plugins:

Spaces Sync Plugin Screen

To manage the settings for DigitalOcean Spaces Sync, we can navigate to our Settings tab, and select DigitalOcean Spaces Sync from the menu:

Settings Tab

DigitalOcean Spaces Sync will now give us options to configure our asset storage:

DO Spaces Sync Configuration

The Connection Settings field in the top half of the screen asks for our Spaces Access Key and Secret. It will then ask for our Container, which will be the name of our Space and the Endpoint.

You can determine the endpoint of your Space based on its URL. For example, if the URL of your Space is https://example-name.nyc3.digitaloceanspaces.com, then example-name will be your bucket/container, and nyc3.digitaloceanspaces.com will be your endpoint.

In the plugin’s interface, the Endpoint section will be pre-filled with the default https://ams3.digitaloceanspaces.com. You should modify this endpoint if your Space lives in another region.

Next, you will be asked for File & Path Settings. In the field marked Full URL-path to files, you can input either a storage public domain, if your files will be stored only on your Space, or a full URL path, if you will store them on your Space and server.

For example, if your WordPress project is located in /var/www/html, and you want to store files on both your server and Space, then you would enter:

  • http://your_server_ip/wp-content/uploads in the Full URL-path to files field
  • /var/www/html/wp-content/uploads in the Local path field

The Storage prefix and Filemask settings are prefilled and do not need to be modified unless you would like to specify certain types of files for your sync.

We will cover the specifics of storing files on your server and Space and your Space alone in the following sections.

Syncing and Saving Files in Multiple Locations

DigitalOcean Spaces Sync offers the option of saving files to your server while also syncing them to your Space. This utility can be helpful if you need to keep files on your server, but would also like backups stored elsewhere. We will go through the process of syncing a file to our Space while keeping it on our server. For this example, we will assume that we have a file called sammy10x10.png that we would like to store in our media library and our Space.

First, navigate to the Settings tab on your WordPress administrative dashboard, and select DigitalOcean Spaces Sync from the menu of presented options.

Next, in the Connections Settings field, enter your Spaces Key and Secret, followed by your Container and Endpoint. Remember, if the URL of your Space is https://example-name.nyc3.digitaloceanspaces.com, then example-name will be your Container, and nyc3.digitaloceanspaces.com will be your Endpoint. Test your connections by clicking the Check the Connection button at the bottom of the Connection Settings field:

Check Connection Button

Now we are ready to fill out the File & Path Settings.

In the Full URL-path to files field, we can enter our full URL path, since we are saving our file on our server and our Space. We will use our server’s IP here, but if you have a domain, you can swap out the IP address for your domain name. For more about registering domains with DigitalOcean, see our tutorial on How To Set Up a Host Name with DigitalOcean. In our case, the Full URL-path to files will be http://your_server_ip/wp-content/uploads.

Next, we will fill out the Local path field with the local path to the uploads directory: /var/www/html/wp-content/uploads.

Because we are working with a single file, we do not need to modify the Storage prefix and Filemask sections. As your WordPress media library grows in size and variety, you can modify this setting to target individual file types using wildcards and extensions such as *.png in the Filemask field.

Your final File & Path Settings will look like this:

Sync Server and Cloud

Be sure to save your configuration changes by clicking the Save Changes button at the bottom of the screen.

Now we can add our file, sammy10x10.png, to our WordPress media library. We will use the wp media import command, which will import the file from our home directory to our WordPress media library. In this case, our home directory will belong to sammy, but in your case, this will be your non-root sudo user. As we move the file, we will use the --path parameter to specify the location of our WordPress project:

  1. wp media import --path=/var/www/html/ /home/sammy/sammy10x10.png

Looking at our WordPress interface, we should now see our file in our Media Library. We can navigate there by following the Media Library tab on the left side of our WordPress administrative dashboard:

Media Library Tab

If we navigate to our Spaces page in the DigitalOcean control panel, we should also see the file in our Space.

Finally, we can navigate to our wp-content/uploads folder, where WordPress will have created a sub-folder with the year and month. Within this folder, we should see our sammy10x10.png file.

Storing Files on Spaces

The DigitalOcean Spaces Sync plugin has an additional option that will allow us to store files only on our Space, in case we would like to optimize space and resources on our server. We will work with another file, sammy-heart10x10.png, and set our DigitalOcean Spaces Sync settings so that this file will be stored only on our Space.

First, let’s navigate back to the plugin’s main configuration page:

DO Spaces Sync Configuration

We can leave the Connection Settings information, but we will modify the File & Path Settings. First, in the Full URL-path to files, we will write the storage public domain. Again, we will use our server IP, but you can swap this out for a domain if you have one: http://uploads.your_server_ip

Next, we will navigate to Sync Settings, at the bottom of the page, and click the first box, which will allow us to “store files only in the cloud and delete after successful upload.” Your final File & Path Settings will look like this:

Sync Cloud Only

Be sure to save your changes by clicking the Save Changes button at the bottom of the screen.

Back on the command line, we will move sammy-heart10x10.png from our user’s home directory to our Media Library using wp media import:

  1. wp media import --path=/var/www/html/ /home/sammy/sammy-heart10x10.png

If we navigate back to our WordPress interface, we will not see sammy-heart10x10.png or sammy10x10.png in our Media Library. Next, if we return to the command line and navigate to our wp-content/uploads directory, we should see that sammy-heart10x10.png is missing from our timestamped sub-folder.

Finally, if we navigate to the Spaces page in the DigitalOcean control panel, we should see both files stored in our Space.

Conclusion

We have covered two different options you can use to store your WordPress media files in DigitalOcean Spaces using DigitalOcean Spaces Sync. This plugin offers additional options for customization, which you can learn more about by reading the developer’s article Sync your WordPress media with DigitalOcean Spaces.

If you would like more general information about working with Spaces, check out our introduction to DigitalOcean Spaces and our guide to best practices for performance on Spaces.

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the author(s)

Kathleen Juell
Kathleen Juell
See author profile

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
20 Comments
Leave a comment...

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Does the plugin move existing media files to DO Spaces and rewrite the media URLs?

It didn’t move existing media to the DO space but it did rewrite all of my media URL’s so all of the media links are broken! Sucks.

So I guess this means you use their plugin you have to start off with their plugin? What should you do with your previous stored assets? How do you manually move them into spaces?

alexdo
Site Moderator
Site Moderator badge
February 27, 2025

You can move any software like s3cmd or CyberDuck to upload your existing media to your Spaces:

https://docs.digitalocean.com/products/spaces/reference/cyberduck/

Regards

alexdo
Site Moderator
Site Moderator badge
February 27, 2025

The plugin will not move the existing media on the Spaces. You can move the existing media manually.

Regards

Love content like this. keep it coming!

“This tutorial assumes that you have a WordPress instance on a server” Does that mean it won`t work for Wordpress managed hosting with SSH access?

Lisa Tagliaferri
DigitalOcean Employee
DigitalOcean Employee badge
July 3, 2018

Yes, it should work with SSH access to your server. If you don’t have full server access, you should still be able to use parts of this tutorial.

alexdo
Site Moderator
Site Moderator badge
February 27, 2025

If you do not have access via ssh you can still install plugins manually via the wp-admin area.

Regards

Hello, Nice article. I works from WP Media Library (Back-end). But i can’t upload in frontend using WP Job Manager and Buddypress. Please help.

alexdo
Site Moderator
Site Moderator badge
February 26, 2025

Heya,

You can inspect the PHP error_log for any logged messages that can provide additional information.

Regards

I notice that this doesn’t seem to sync all folders and files from the WP /uploads/ directory. Only the typical WP year/month directories for me are syncing to Spaces. However I need other directories and files within the WP /uploads/ to sync. Any idea how to make that happen using the DigitalOcean Spaces Sync Settings Plugin? Theme CSS and some other Plugin files often get put in this /uploads/ directory and don’t follow the same naming convention as base WP media files.

Were you able to resolve this issue? If yes, how did you do it? Thanks in advance!

alexdo
Site Moderator
Site Moderator badge
February 27, 2025

You can give it a try with another plugin and check if the other directories will be in sync as well.

I can recommend you to try this plugin:

WP Offload Media Lite for Amazon S3, DigitalOcean Spaces, and Google Cloud Storage

This plugin automatically copies images, videos, documents, and any other media added through WordPress’ media uploader to DigitalOcean Spaces

Regards

alexdo
Site Moderator
Site Moderator badge
February 27, 2025

I would assume the plugin might have some limitations when it comes to sync other folders different from the base structure.

I can recommend you to try this plugin:

WP Offload Media Lite for Amazon S3, DigitalOcean Spaces, and Google Cloud Storage

This plugin automatically copies images, videos, documents, and any other media added through WordPress’ media uploader to DigitalOcean Spaces

Regards

I want to store only images on a server. I specified: ‘files.my_domain_name’ in full url path to files. Files uploaded correctly. But I don’t see them by files.my_domain_name URL. Should I create a subdomain DNS record for this to work?

jarland
DigitalOcean Employee
DigitalOcean Employee badge
April 10, 2019

Greetings! I just wanted to take a moment to let you know that we have just released custom subdomains for Spaces. I hope that you find this to meet your needs! You can read more about it on our blog post here: https://blog.digitalocean.com/custom-subdomains-for-spaces-cdn-endpoints

@ltagliaferri What should we do if we want to use this but also load balance?

alexdo
Site Moderator
Site Moderator badge
February 26, 2025

You would still need to install a plugin. , I can recommend you to try this plugin:

WP Offload Media Lite for Amazon S3, DigitalOcean Spaces, and Google Cloud Storage

This plugin automatically copies images, videos, documents, and any other media added through WordPress’ media uploader to Amazon S3, DigitalOcean Spaces or Google Cloud Storage. It then automatically replaces the URL to each media file with their respective Amazon S3, DigitalOcean Spaces or Google Cloud Storage URL or, if you have configured Amazon CloudFront or another CDN with or without a custom domain, that URL instead. Image thumbnails are also copied to the bucket and delivered through the correct remote URL.

Regards

for wordpress MU this does store the images in Spaces BUT NOT serving images in wordpress shows error on uploads BUT STILL Stores the images in Spaces

alexdo
Site Moderator
Site Moderator badge
February 26, 2025

You can inspect the PHP error_logs for more detailed errors. I haven’t looked into configuring this in WordPress multisite, but if the upload works fine then serving the images might be related to permalinks or paths.

Regards

This plugins is not good enough.

Many CDN plugins can modify media base address on the fly. How utility have to install this for a working site?

I agree with this comment 100% - WP Offload Media can do it easily so copy their UI. I assume you guys have a team or money to pay a wordpress developer for this.

alexdo
Site Moderator
Site Moderator badge
February 11, 2025

Heya, I can recommend you to try this plugin:

WP Offload Media Lite for Amazon S3, DigitalOcean Spaces, and Google Cloud Storage

This plugin automatically copies images, videos, documents, and any other media added through WordPress’ media uploader to Amazon S3, DigitalOcean Spaces or Google Cloud Storage. It then automatically replaces the URL to each media file with their respective Amazon S3, DigitalOcean Spaces or Google Cloud Storage URL or, if you have configured Amazon CloudFront or another CDN with or without a custom domain, that URL instead. Image thumbnails are also copied to the bucket and delivered through the correct remote URL.

Regards

To manually move old media to spaces, use:

cd /path/to/wp-content/uploads
s3cmd put * --acl-public --add-header=Cache-Control:max-age=86400 --recursive --continue-put s3://name/of/bucket/wp-content/uploads/

Work like a charm: https://www.digitalocean.com/docs/spaces/resources/s3cmd/

alexdo
Site Moderator
Site Moderator badge
February 11, 2025

Thanks for sharing this!

You can also add the --skip-existing argument to prevent copying the already existing files and overwriting them.

Regards

The DigitalOcean Spaces Sync plugin seems bugged when uploading images with duplicate filenames. It does not append any extra characters to the new filename so the new file actually never gets uploaded but a new reference is made to it inside of the wordpress media library.

Has anyone ran into those or found a solution?

alexdo
Site Moderator
Site Moderator badge
February 11, 2025

Heya, I can recommend you to try this plugin:

WP Offload Media Lite for Amazon S3, DigitalOcean Spaces, and Google Cloud Storage

This plugin automatically copies images, videos, documents, and any other media added through WordPress’ media uploader to Amazon S3, DigitalOcean Spaces or Google Cloud Storage. It then automatically replaces the URL to each media file with their respective Amazon S3, DigitalOcean Spaces or Google Cloud Storage URL or, if you have configured Amazon CloudFront or another CDN with or without a custom domain, that URL instead. Image thumbnails are also copied to the bucket and delivered through the correct remote URL.

Regards

https://wordpress.org/plugins/do-spaces-sync/

“This plugin has been closed as of October 27, 2019 and is not available for download. This closure is temporary, pending a full review.”

alexdo
Site Moderator
Site Moderator badge
February 11, 2025

Heya, I can recommend you to try this plugin:

WP Offload Media Lite for Amazon S3, DigitalOcean Spaces, and Google Cloud Storage

This plugin automatically copies images, videos, documents, and any other media added through WordPress’ media uploader to Amazon S3, DigitalOcean Spaces or Google Cloud Storage. It then automatically replaces the URL to each media file with their respective Amazon S3, DigitalOcean Spaces or Google Cloud Storage URL or, if you have configured Amazon CloudFront or another CDN with or without a custom domain, that URL instead. Image thumbnails are also copied to the bucket and delivered through the correct remote URL.

Regards

DigitalOcean Spaces Sync plugin store credentials in plain text. Anyone with the permission to view “Settings” can easily get the credentials then they could manipulate your whole backup server. This plugin shouldn’t be in official documentation until it is fixed!

alexdo
Site Moderator
Site Moderator badge
February 11, 2025

Heya, I can recommend you to try this plugin:

WP Offload Media Lite for Amazon S3, DigitalOcean Spaces, and Google Cloud Storage

This plugin automatically copies images, videos, documents, and any other media added through WordPress’ media uploader to Amazon S3, DigitalOcean Spaces or Google Cloud Storage. It then automatically replaces the URL to each media file with their respective Amazon S3, DigitalOcean Spaces or Google Cloud Storage URL or, if you have configured Amazon CloudFront or another CDN with or without a custom domain, that URL instead. Image thumbnails are also copied to the bucket and delivered through the correct remote URL.

Regards

I created a CDN and have everything connected and working as expected. The website has 1000’s of images and I was curious if it were possible to upload all them to spaces then sync them to wordpress. Is this possible?

alexdo
Site Moderator
Site Moderator badge
February 11, 2025

Heya, I can recommend you to try this plugin:

WP Offload Media Lite for Amazon S3, DigitalOcean Spaces, and Google Cloud Storage

This plugin automatically copies images, videos, documents, and any other media added through WordPress’ media uploader to Amazon S3, DigitalOcean Spaces or Google Cloud Storage. It then automatically replaces the URL to each media file with their respective Amazon S3, DigitalOcean Spaces or Google Cloud Storage URL or, if you have configured Amazon CloudFront or another CDN with or without a custom domain, that URL instead. Image thumbnails are also copied to the bucket and delivered through the correct remote URL.

Regards

“…be sure to use your non-root sudo user”

I had no idea how to do this, but this article was helpful:

How To Create a New Sudo-enabled User on Ubuntu 18.04

Bobby Iliev
Site Moderator
Site Moderator badge
July 30, 2024

In addition to the above, I could also suggest following the initial server setup guide which includes other good practices you could do on a new server:

https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu

The command to install Digital Ocean Spaces Sync ('wp plugin install do-spaces-sync") failed. It couldn’t create the directory and ‘do-spaces-sync’ plugin could not be found.

I was, however, able to install the plugin from Wordpress

alexdo
Site Moderator
Site Moderator badge
February 11, 2025

I’m glad that this worked out for you. The do-sync plugin however appears to be not maintained from a long time.

I can recommend you to try this one:

WP Offload Media Lite for Amazon S3, DigitalOcean Spaces, and Google Cloud Storage

The last update was from 3 weeks ago and WP Engine usually regularly update their plugins.

Hope that this helps!

Set Full URL-path to files: to https://uploads.your_server_ip will not work unless you manage the subdomain to the space, so if you do not set the subdomain, fill the field with this value: https://Bucket-Space-Name.nyc3.cdn.digitaloceanspaces.com/

do not forget to replace nyc3 with the region of the space, and remove cdn if you not enable it for the space

alexdo
Site Moderator
Site Moderator badge
February 11, 2025

Heya,

You can also check our article on how to add a custom subdomain:

https://docs.digitalocean.com/products/spaces/how-to/customize-cdn-endpoint/#add-a-custom-subdomain

Regards

That plugin was out of update, and it does not work when checking the connection.

alexdo
Site Moderator
Site Moderator badge
February 11, 2025

Heya, I can recommend you to try this one:

WP Offload Media Lite for Amazon S3, DigitalOcean Spaces, and Google Cloud Storage

The last update was from 3 weeks ago and WP Engine usually regularly update their plugins.

Hope that this helps!

Please help My origin Endpoint is https://myendpoint.sgp1.digitaloceanspaces.com, i have a folder name “location” How can i set up my upload file go to exact Local path: https://myendpoint.sgp1.digitaloceanspaces.com/location/2024

alexdo
Site Moderator
Site Moderator badge
February 11, 2025

Heya,

This depends from the method you use to upload the file. Are you manually uploading it or using boto3 or other client or script?

Regards

The plugin is not working in 2024. It is outdated and has no support at all. It’s a shame that DigitalOcean does not offer an official plugin for this specific need.

alexdo
Site Moderator
Site Moderator badge
February 11, 2025

Heya, I can recommend you to try this one:

WP Offload Media Lite for Amazon S3, DigitalOcean Spaces, and Google Cloud Storage

The last update was from 3 weeks ago and WP Engine usually regularly update their plugins.

Hope that this helps!

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.