Apr 2, 2023 Last modified May 25, 2023 Using Cloudflare R2 as your primary storage on Owncloud A guide on how to set up Cloudflare R2 on Owncloud. cloudflare · 5 min read

I have a compute instance that is running Owncloud, which I use to backup my files and whatnot. The problem is, my instance has very little storage to actually host anything.

Then I had an idea… what if I could hook up Cloudflare’s R2 service to Owncloud?

Table of contents

Preamble

This guide assumes you’re running an instance of Owncloud on a Docker container using docker-compose.

If you don’t have an instance of Owncloud running on Docker, follow these steps:

Creating an R2 bucket

Go to your Cloudflare dashboard and navigate to the R2 page.

The R2 page on your Cloudflare dashboard, highlighted in red.
The R2 page on your Cloudflare dashboard, highlighted in red.

You’ll want to create a bucket. Make sure you give this bucket a unique name, because you won’t be able to change it afterwards!

For the purposes of this guide, I’ll stick with the bucket name owncloud-instance.

The name for your R2 bucket.
The name for your R2 bucket.

Once you’re done with that, head back to the R2 page, and click on the Manage R2 API Tokens link.

At the time of writing this guide, the link should be in the upper right corner.

The "Manage R2 API tokens" link.
The "Manage R2 API tokens" link.

Then, click on the Create API token button.

Bucket creation options

Let’s go through each of the options on the page:

When you’re done, click on the Create API Token button.

You’ll be able to see your Access Key ID and Secret Access Key values here. Keep them somewhere safe, as you will not be able to see them again!

The R2 API token being successfully created with the "Access Key ID" and "Secret Access Key" values provided.
The R2 API token being successfully created with the "Access Key ID" and "Secret Access Key" values provided.

Installing the S3 extension for Owncloud

Once you’re done creating an R2 bucket, head over to your Owncloud admin dashboard.

Click on the menu bar located in the upper left corner, and select the Market tab.

The Market tab on your Owncloud instance.
The Market tab on your Owncloud instance.

Scroll down until you find the S3 Primary Object Storage extension, and install it.

The S3 Primary Object Storage extension on the Owncloud Marketplace.
The S3 Primary Object Storage extension on the Owncloud Marketplace.

Note: You’ll want this extension, and not the extension called External Storage: S3!

Setting up R2 for your Owncloud instance

Before proceeding any further, make sure you back up all your data. Proceeding with the steps below will wipe any data you had on your Owncloud instance.

You’re done with all that? Great. It’s time to configure R2 to work on your Owncloud instance.

Run the following command to access the filesystem of your Owncloud Docker instance:

Terminal
> docker exec -t -i owncloud_server /bin/bash

Head over to the config folder. The config folder should have the following files:

Terminal
> ls
config.php  objectstore.config.php  overwrite.config.php

We’re looking to edit the config.php file. Add the following to the configuration file:

config.php
'objectstore' => [
  'class' => '\\OC\\Files\\ObjectStore\\S3',
  'arguments' => [
    'bucket' => 'BUCKET',
    'autocreate' => true,
    'key'    => 'ACCESS_KEY_ID',
    'secret' => 'SECRET_ACCESS_KEY',
    'hostname' => 'ACCOUNT_ID.r2.cloudflarestorage.com',
    'port' => 443,
    'use_ssl' => true,
    'region' => 'auto',
  ],
]

S3 configuration options

Replace the following:

The R2 bucket hostname.
The R2 bucket hostname.

Then, run docker restart owncloud_server to apply the changes.

And that’s it! Log back in to your Owncloud admin dashboard, and your instance should utilize your Cloudflare R2 bucket as its primary storage.


Overall, it’s pretty painless for your Owncloud instance to utilize Cloudflare’s R2 service.

I will warn you though, Cloudflare’s base plan for R2 only includes 10 GB of storage per month.

Pricing for Cloudflare's R2 service.
Pricing for Cloudflare's R2 service.

But it all depends if you’re fine with that. :)

Hey! If you’re still here…

This is the first time I’m writing a blog post of this sort. Let me know if I did well, or if there’s anything I can improve with future blog posts. Thank you! ❤️

Comments Discuss this article with others here!