Sitemap

Member-only story

Integrating Cloudflare R2 with Laravel: A Step-by-Step Guide

How to Store and Serve Files in Laravel Using Cloudflare R2

3 min readApr 1, 2025

--

Press enter or click to view image in full size
Image from Cloudflare

If you’re running a Laravel project and need affordable object storage, Cloudflare R2 is a great option. It works similarly to AWS S3 but without egress fees, which makes it ideal for projects that need to serve a lot of data. The only catch? Laravel doesn’t support R2 out of the box, so you’ll need to configure it manually.

This guide walks you through setting up Cloudflare R2 with Laravel. We’ll cover everything from creating an R2 bucket to configuring Laravel so you can store and retrieve files with ease.

Step 1: Set Up Cloudflare R2

Before Laravel can store files in Cloudflare R2, you need an R2 bucket and API credentials. Here’s how to get started:

  1. Log into Cloudflare and navigate to the R2 section.
  2. Create a new bucket and give it a unique name.
  3. Generate API credentials:
  • Go to ‘API Tokens’ in your Cloudflare dashboard.
  • Create a new token with permissions to read and write to R2.
  • Copy the Access Key ID and Secret Access Key somewhere safe. You’ll need them in Laravel.

--

--

Hafiq Iqmal
Hafiq Iqmal

Written by Hafiq Iqmal

Tech Lead | Software Engineer | Laravel Enthusiasts | Tech writer | UiTM Alumni | Husband | Father of a beautiful daughter | 🇲🇾 Malaysia