PHPackages                             magezero/magento2-cloudflare-r2-storage - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. magezero/magento2-cloudflare-r2-storage

ActiveMagento2-module[File &amp; Storage](/categories/file-storage)

magezero/magento2-cloudflare-r2-storage
=======================================

Cloudflare R2 storage adapter for Magento 2 media storage

1.0.0(3mo ago)028↓100%OSL-3.0PHP ^7.4 || ^8.0

Since Feb 24Pushed 1mo agoCompare

[ Source](https://github.com/zynqa/module-cloudflare-r2-storage)[ Packagist](https://packagist.org/packages/magezero/magento2-cloudflare-r2-storage)[ RSS](/packages/magezero-magento2-cloudflare-r2-storage/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (1)Dependencies (5)Versions (2)Used By (0)

MageZero Cloudflare R2 Storage for Magento 2
============================================

[](#magezero-cloudflare-r2-storage-for-magento-2)

Magento 2 module for Cloudflare R2 media storage. Designed for containerized deployments where media is stored in R2 and served via CDN.

Compatibility
-------------

[](#compatibility)

### Requirements

[](#requirements)

- **PHP**: 8.1, 8.2, 8.3, or 8.4
- **Magento**: 2.4.6 or later

### Tested Versions

[](#tested-versions)

MagentoPHPPHPStanUnit TestsIntegration Tests2.4.6-p98.1-✓✓2.4.7-p48.2-✓✓2.4.8-p38.3✓✓✓2.4.8-p38.4✓✓-Unit tests run on all PHP versions to ensure syntax compatibility. PHPStan runs on PHP 8.3 and 8.4 for static analysis. Integration tests run once per Magento version to verify R2 functionality.

Features
--------

[](#features)

- **R2 as Media Storage Backend** - All media files stored in Cloudflare R2
- **CDN-First Serving** - Images served directly from R2/CDN
- **Storage-Only Focus** - Module handles storage; Magento core handles image processing
- **Redis Caching** - CDN file existence checks cached for optimal performance
- **Docker/Kubernetes Ready** - Works with ephemeral containers using tmpfs mounts
- S3-compatible API with Cloudflare R2 optimizations

Installation
------------

[](#installation)

Install with Composer in your Magento project:

```
composer require magezero/magento2-cloudflare-r2-storage
bin/magento module:enable MageZero_CloudflareR2
bin/magento setup:upgrade
bin/magento cache:flush
```

Configuration
-------------

[](#configuration)

1. **Configure R2 Connection**:

    - Go to **Stores &gt; Configuration &gt; Advanced &gt; System &gt; Media Storage Configuration**
    - Set **Media Storage** to **Cloudflare R2 (S3 Compatible)**
2. **Configure R2 Credentials**:

    - Go to **Stores &gt; Configuration &gt; MageZero &gt; Cloudflare R2 Storage**
    - Fill in:
        - Account ID (optional if you provide endpoint)
        - Endpoint (e.g. `https://.r2.cloudflarestorage.com`)
        - Region (use `auto` for R2)
        - Bucket
        - Access Key ID / Secret Access Key
        - Optional key prefix (e.g. `media`)
3. **Configure CDN/Public URL** (required):

    - Set **Base Media URL (Secure)** to your R2 public domain or Cloudflare CDN URL
    - Example: `https://media.example.com` or `https://pub-xxxxx.r2.dev`
    - Optionally set **Base Media URL (Unsecure)** if needed
4. **Configure Caching** (optional):

    - Adjust **File Existence Cache TTL** (default: 3600 seconds)
    - This caches CDN HEAD requests in Redis for optimal performance
5. **Configure Cloudflare R2**:

    - Set your R2 bucket to **Public** or configure a [custom domain](https://developers.cloudflare.com/r2/buckets/public-buckets/)
    - Enable Cloudflare CDN caching for best performance

Container Deployment
--------------------

[](#container-deployment)

For containerized deployments (Docker Swarm, Kubernetes), mount a writable tmpfs on `pub/media`:

**Docker Compose / Swarm:**

```
services:
  php-fpm:
    volumes:
      - type: tmpfs
        target: /var/www/html/pub/media
```

**Kubernetes:**

```
volumes:
  - name: media-cache
    emptyDir: {}
volumeMounts:
  - name: media-cache
    mountPath: /var/www/html/pub/media
```

**How it works:**

1. Magento core writes to `pub/media` (tmpfs - writable, ephemeral)
2. Module syncs files to R2 for persistent storage
3. Images served from R2/CDN
4. On container restart, cache regenerates as needed

Product Image Resizing
----------------------

[](#product-image-resizing)

**Pre-generation (Recommended for production):**

```
bin/magento catalog:images:resize
```

This generates all product image sizes using Magento core, then syncs them to R2.

**On-demand generation:**When a requested image size doesn't exist in R2, Magento core generates it to the local tmpfs, and subsequent requests are served from R2/CDN once synced.

Architecture
------------

[](#architecture)

This module focuses solely on **storage operations**:

- Uploading files to R2
- Downloading files from R2
- Syncing locally generated cache to R2
- File existence checks (cached in Redis)

All image processing (resizing, watermarks, swatch generation) is handled by **Magento core**. The module intercepts storage operations, not image manipulation.

Notes
-----

[](#notes)

- The module uses path-style endpoints by default, which is recommended for R2.
- The **Flush Catalog Images Cache** action clears cached resized images in R2.
- Redis or similar cache backend recommended for file existence caching.
- R2 bucket must be public or have custom domain configured.
- **CAPTCHA images**: Magento generates CAPTCHA images locally under `pub/media/captcha/**`. If your **Base Media URL** points at R2/CDN, those images must also exist in R2 to avoid 404s (e.g. admin login CAPTCHA). This module uploads generated CAPTCHA images to R2 when R2 storage is selected. Consider adding an R2 lifecycle rule to expire/delete objects under the `captcha/` prefix.

License
-------

[](#license)

OSL-3.0

Credits
-------

[](#credits)

- AWS SDK for PHP (S3 compatible client)
- [extdn/github-actions-m2](https://github.com/extdn/github-actions-m2) (CI workflows)

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance86

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 Bus Factor1

Top contributor holds 96.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

106d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1080386?v=4)[Raul Watson](/maintainers/diazwatson)[@diazwatson](https://github.com/diazwatson)

---

Top Contributors

[![cmtickle](https://avatars.githubusercontent.com/u/25080134?v=4)](https://github.com/cmtickle "cmtickle (31 commits)")[![diazwatson](https://avatars.githubusercontent.com/u/1080386?v=4)](https://github.com/diazwatson "diazwatson (1 commits)")

### Embed Badge

![Health badge](/badges/magezero-magento2-cloudflare-r2-storage/health.svg)

```
[![Health](https://phpackages.com/badges/magezero-magento2-cloudflare-r2-storage/health.svg)](https://phpackages.com/packages/magezero-magento2-cloudflare-r2-storage)
```

###  Alternatives

[league/flysystem-aws-s3-v3

AWS S3 filesystem adapter for Flysystem.

1.7k277.8M952](/packages/league-flysystem-aws-s3-v3)[run-as-root/magento2-prometheus-exporter

Magento2 Prometheus Exporter

68353.9k](/packages/run-as-root-magento2-prometheus-exporter)[andersundsehr/aus-driver-amazon-s3

Provides a FAL driver for the Amazon Web Service AWS S3.

24269.9k](/packages/andersundsehr-aus-driver-amazon-s3)[mreduar/s3m

Multipart Uploads using Laravel and AWS S3

174.2k](/packages/mreduar-s3m)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
