Self Hosting: Nextcloud with DigitalOcean Spaces for Main Storage

Home ServerSelf Hosted

Written by:

It has been over a year since I originally set up my own self-hosted cloud using Nextcloud. I am happy to report back that I absolutely love it, and it has run flawlessly without error for this period. It is central to my personal infrastructure and I have come to rely on it, I would recommend Nextcloud to anyone.

My only issue is that I need more space! So when it came time to upgrade to the latest version of Nextcloud, I took this as an opportunity to switch my main storage to the S3-compatible object storage that DigitalOcean calls Spaces.

OBJECT STORAGE

When I originally set up Nextcloud, I chose a traditional volume as my storage. Actually, I don’t think object storage was offered at that point. Anyways, a volume acts like a disk. But that means I’m paying for the whole disk, not just what I’m using. And if I need to resize it… well, same process as a disk, even if it’s a virtual one.

So enter object storage, the most commonly known service being Amazon’s S3. There are many other S3-compatible providers, including ones you can host your self. The storage is much, much cheaper ($5 for 250gb on DigitalOcean, with GB after that at $0.02) than the equivalent as volume storage. You don’t have to commit (or pay for) a static amount of space, but only what you use. There are other benefits you can read about.


NEXTCLOUD + SPACES

I use DigitalOcean for my host, and couldn’t find a working configuration example for Nextcloud 16 to use their S3-like object storage known as Spaces. So here is the process I went through:

  1. Set up a Droplet VM with DigitalOcean
  2. Add a Space and generate API keys
  3. Follow my Nextcloud Docker Compose guide to get it up and running
  4. Edit the configuration file to switch to object storage

You should not do this to an existing Nextcloud installation. Switching from a volume to object storage will wipe out your existing data. You need to do this from scratch, or make backups and carefully plan how you will migrate your existing data and users

I’ve also been extremely happy with DigitalOcean as my host for things I run outside my house. Click here for $10 credit to work on your own projects on DigitalOcean’s infrastructure.

RELATED >>  Hardware: Odroid XU4 as Plex Media Server

SETTING UP THE SPACE

Creating a Space is pretty straight forward, just choose a data center (your region/endpoint), a name (the S3 ‘bucket’), and what project you want to associate it with.

Now you have an empty Space, but don’t upload anything. Nextcloud needs exclusive use of this.

Space is a lonely place

The assets in the Space are served over a S3-compatible API. In order to access that API, we need to generate some API keys for Nextcloud to use.

In your DO Manager, select “API” and you will see “Spaces access keys”. Generate New Key

That’s pretty much it, now on to configuring Nextcloud

CONFIGURING NEXTCLOUD

At this point you should have a working and accessible Nextcloud installation, but it is not using the object storage yet. Shut Nextcloud down, and then edit your main Nextcloud config file (config/config.php relative to your installation).

At the end of your config.php file, but before the last closing ); add

'objectstore' => array(
        'class' => '\\OC\\Files\\ObjectStore\\S3',
        'arguments' => array(
                'bucket' => 'NAME_OF_SPACE',
                'key'    => 'SECRET',
                'secret' => 'SECRET',
                'hostname' => 'REGION.digitaloceanspaces.com',
                'region' => 'REGION',
                'port' => 443,
                'use_ssl' => true,
                // required for some non Amazon S3 implementations
                'use_path_style'=>true
        ),
),

The bucket name is the name of the Space. So above, “nextcloudtest”.

The key and the secret come from the API manager.

The hostname is the datacenter you chose. So if I chose SFO2 above the URL is sfo2.digitaloceanspaces.com and the region is also sfo2.

If you’re not sure, you can check the ‘Endpoint’ in the Spaces Settings

Restart Nextcloud and you should be looking at a blank files page. Upload to it, and you’ll see the size of your Space grow in your DO account.

You’re now all set with object storage as your backend, with no limit to the amount of data you can store in the cloud.

RESOURCES



Leave a Reply

Your email address will not be published. Required fields are marked *