A link to my avatar. The character displayed here is Silver Wolf from the videogame Honkai: Star Rail.

Sapphic Angels

(she/it/they)

Using Cloudflare R2 as your primary storage on Owncloud

A guide on how to set up Cloudflare R2 on Owncloud and use it as your storage.

April 2, 2023

#cloudflare #owncloud

4 min read

Introduction

We have a compute instance that is running Owncloud, which we use to backup our files and whatnot. While we were configuring the instance and uploading our files, we quickly realized that our instance’s storage is very limited and did not have enough space to actually house all of our potential future backups.

But then we had an idea: what if we could hook up Cloudflare’s R2 service to Owncloud?

Stick with us as we show you how to do exactly that in this article.

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 a bucket

Go to your Cloudflare dashboard and navigate to the R2 page. Then click on the Create bucket button.

💡 When creating 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, we’ll stick with the bucket name owncloud-instance.

The unique name for your Cloudflare R2 bucket.
The unique name for your Cloudflare R2 bucket.

Once you’re done with that, head back to the R2 page, click on the Manage R2 API Tokens link and 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

You’ll want to replace the following options:

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.

Conclusion

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

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

The pricing plans for Cloudflare's R2 service.
The pricing plans 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 we’re writing a blog post of this sort. Let us know if we did well, or if there’s anything we can improve with future blog posts. Thank you! ❤️