How do I store WordPress Assets on DigitalOcean Spaces?
This is a support request that we sometimes receive as a part of our Server Management Services.
Users often choose an object storage solution for static content on a WordPress site to free up space on the server.
Let us today discuss the steps to perform this task with DigitalOcean Spaces.
Store WordPress assets on DigitalOcean Spaces?
WordPress sites include a lot of static content like images and videos etc. These tend to occupy a large share of the server storage and thus slows down the server.
The object storage service can be used to store large amounts of diverse, unstructured data securely. Digital Ocean Spaces is one of them.
Using object storage for static resources can optimize site performance by freeing up space and resources on your servers.
Let us now look into the steps to perform store WordPress assets DigitalOcean.
Modifying WordPress Permissions
Most of the static files in wordpress is stored inside the iploads folder. Thus it is important that the wp-content/uploads folder exists and has the correct permissions. You can create it with the mkdir command using the -p flag in order to create the folder if it does not exist, and avoid throwing an error if it does. Here “/var/www/html/” is the document root of wordpress site.
$ sudo mkdir -p /var/www/html/wp-content/uploads
You can now set permissions on the folder. First, set the ownership to your user (non-root sudo user), and group ownership to the www-data group:
$ sudo chown -R bob:www-data /var/www/html/wp-content/uploads
Next, establish the permissions that will give the web server write access to this folder:
$ sudo chmod -R g+w /var/www/html/wp-content/uploads
We will now be able to use plugins to create a store in object storage for the assets in the wp-content/uploads folder, and to engage with assets from the WordPress interface.
Installing DigitalOcean Spaces Sync to store WordPress assets
The first step in using DigitalOcean Spaces Sync will be to install it in WordPress folder. We can navigate to the plugin folder within our WordPress directory:
$ cd /var/www/html/wp-content/plugins
From here, we can install DigitalOcean Spaces Sync and activate it using the wp commands:
$ wp plugin install do-spaces-sync
$ wp plugin activate do-spaces-sync
DigitalOcean Spaces Sync will be now shown in our list of activate plugins in the wordpress dashboard.
The Settings tab of the DigitalOcean Spaces Sync plugin will now give us options to configure our asset storage.
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.
Edit the prefilled endpoint in the plugin’s interface 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.
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.
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. Test your connections by clicking the Check the Connection button at the bottom of the Connection Settings field.
In the File & Path Settings, full URL path can be entered in the Full URL-path, since we are saving our file on our server and on 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. 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.
To sync large volume of files at once, modify the storage prefix and Filemask sections to target individual file types using wildcards and extensions such as *.png in the Filemask field.
Be sure to save your configuration changes by clicking the Save Changes button at the bottom of the screen.
Now if we add a file with the respective extension to wordpress, it will be synced to the Space as well.
Storing WordPress assets digital ocean Spaces
The DigitalOcean Spaces Sync plugin has an additional option that will allow us to store files only on our Space,
For this in the plugin’s configuration page, in the 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 a successful upload.
Finally, now if we add a file to wordpress, it will be missing from the timestamp folder, but will be present in the DigitalOcean Spaces.
[Need any further assistance to store WordPress assets on DigitalOcean Spaces? – We’re available 24*7]
Conclusion
In short, using object storage for static resources can optimize site performance by freeing up space and resources on your servers. Today, we saw how our Support Engineers perform this task.
0 Comments