Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

DimZ's avatar
Level 4

Storage via Cloudflare R2

Hi all,

I would like to use Cloudflare R2 instead of S3 to store my files. It sounds S3 compatible, so I just created a R2 file system based on S3 driver, but it seems not working.

Maybe I missed something?

filesystems.php

        'r2' => [
            'driver' => 's3',
            'key' => env('CLOUDFLARE_R2_ACCESS_KEY'),
            'secret' => env('CLOUDFLARE_R2_SECRET_KEY'),
            'region' => env('CLOUDFLARE_R2_REGION'),
            'bucket' => env('CLOUDFLARE_R2_BUCKET'),
            'endpoint' => env('CLOUDFLARE_R2_ENDPOINT'),
            'url' => env('CLOUDFLARE_R2_URL'),
            'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false),
            'throw' => false,
        ],

.env

CLOUDFLARE_R2_ACCESS_KEY="MY_KEY"
CLOUDFLARE_R2_SECRET_KEY="MY_SECRET"
CLOUDFLARE_R2_REGION="eu-west-1"
CLOUDFLARE_R2_BUCKET="cdn-example-com"
CLOUDFLARE_R2_ENDPOINT="https://XXX.r2.cloudflarestorage.com"
CLOUDFLARE_R2_URL="https://cdn.example.com"

tinker

Storage::disk('r2')->get('A.jpg');
League\Flysystem\UnableToCheckDirectoryExistence with message 'Unable to check existence for: A.jpg'
0 likes
5 replies
thamjeedlal's avatar
Level 1

When using the S3 API, the region for an R2 bucket is auto. For compatibility with tools that do not allow you to specify a region, an empty value and us-east-1 will alias to the auto region.

3 likes
DimZ's avatar
Level 4

@thamjeedlal it was as simple as that! Thank you I didn't know that, it works perfectly with CLOUDFLARE_R2_REGION="us-east-1" 🥰

2 likes
OstapBrehin's avatar

auto value works for a default region in R2. In my case:

AWS_DEFAULT_REGION=auto
kurucu's avatar

How are you making this CLOUDFLARE_R2_URL="https://cdn.example.com" work?

basherdesigns's avatar

@kurucu You setup a custom domain in Cloudflare bucket settings and update your DNS records.

Please or to participate in this conversation.