OCMLABS/MODULE-CLOUDFLARE · INSTALLATION

Installing the Cloudflare module, creating the API token and connecting your zone

  • Magento
  • Adobe Commerce
  • Hyvä

Requirements

  • Magento Open Source or Adobe Commerce 2.4.4 or later
  • PHP 8.1 or later
  • A Cloudflare zone proxying the storefront (the orange cloud is on for the storefront hostnames)
  • A working Magento cron, so the purge queue consumer and the hourly health checks run

Install via Composer

Terminal window
composer require ocmlabs/module-cloudflare
bin/magento module:enable OCMLabs_Cloudflare
bin/magento setup:upgrade
bin/magento setup:di:compile
bin/magento cache:clean

In production mode also run bin/magento setup:static-content:deploy.

NOTE /

Run a full bin/magento cache:clean after installing or upgrading, not only a flush of the full page cache. The module registers plugins and a RequireJS map, and both stay stale until the config and layout caches are cleaned.

Verify the installation

Terminal window
bin/magento module:status OCMLabs_Cloudflare

In the admin, System > Cloudflare > Dashboard should appear. Nothing changes on the storefront yet: the module is disabled by default and edge caching is a separate switch.

Create the API token

In Cloudflare go to My Profile > API Tokens > Create Token > Create Custom Token for a user-owned token, or Manage Account > Account API Tokens for an account-owned token. Both work; the module verifies each kind at the right endpoint. Give it these permissions, scoped to the zones the store uses:

PermissionWhat the module uses it for
Zone:ReadLook up the zone, its plan and development mode
Zone:Cache PurgePurge by tag, URL, prefix or everything
Zone:Settings:ReadHealth checks on zone settings (SSL mode, Rocket Loader and so on)
Zone:Settings:EditTurn development mode on and off
Zone:Cache Rules:EditApply the recommended cache rules. This is separate from Settings:Edit
Analytics:ReadThe Analytics tab

Zone:Cache Rules:Edit is the one people miss. Without it everything works except applying rules; you can paste the rules by hand instead, as described on the Cache Rules page.

Connect the store

Everything lives under Stores > Configuration > OCMLabs > Cloudflare.

  1. General (default scope): set Enable Cloudflare Integration to Yes and paste the API token. Account ID is optional and is detected from the token. Tokens created or rolled since 2026 carry a prefix and checksum (cfut_... user-owned, cfat_... account-owned) and are longer than the older 40-character form; paste the whole string. Click Test Connection.
  2. Zone (website scope): switch the scope to each website and click Detect Zone, or paste the Zone ID. Each website can map to its own zone, and the API token can be overridden per website if a website lives on a different Cloudflare account.
  3. Storefront Hosts is optional. Leave it blank and the hosts come from the website’s base URLs. Fill it in, one host per line, if the public host differs.
  4. Storefront Origin is optional. It is only used by the “Origin sends edge cache headers” health check, which fetches a page straight from your origin. Use a host, host:port, an IP or a URL, for example https://203.0.113.7 or origin.example.com:8443.

Magento in a subdirectory (a base URL such as https://www.example.com/shop/) needs no extra setting. The module reads the path from the base URLs and keeps every cache rule inside it, so the rest of the host is left alone.

The full field reference is on the System Settings page.

Start the purge queue consumer

Purges are queued by default and sent by the ocmlabsCloudflarePurge consumer on Magento’s built-in db queue connection. No RabbitMQ is needed, but the consumer has to run or tags pile up in the queue and Cloudflare keeps serving stale pages.

Option 1: Magento cron (default). If app/etc/env.php has no cron_consumers_runner key, Magento’s cron starts every registered consumer, including this one. To scope it explicitly:

'cron_consumers_runner' => [
'cron_run' => true,
'max_messages' => 10000,
'consumers' => ['ocmlabsCloudflarePurge'],
],

Option 2: process supervisor. Run it as a long-lived process under supervisord or similar:

Terminal window
bin/magento queue:consumers:start ocmlabsCloudflarePurge --max-messages=10000

The “Purge queue consumer” health check tells you whether purges are going out.

Enable the module’s cache type

Go to System > Cache Management, select OCMLabs Cloudflare, choose Enable and submit. The module caches zone details, analytics results and the purge rate limiter’s request count in this cache type. With it disabled every dashboard view and health run calls Cloudflare again, and the rate limiter cannot pace purges against your plan’s limit.

Check which caching application you use

Go to Stores > Configuration > Advanced > System > Full Page Cache and look at Caching Application.

  • Built-in Cache: the module sets the edge headers itself in PHP. Nothing outside Magento needs to change. Go straight to the next section.
  • Varnish Cache: nothing to change in Varnish either. The module sends Cloudflare its own caching header, which passes through stock and customised VCL untouched. Flush Magento’s cache once after turning edge caching on (step 3 below). See Varnish for the details.

Keep the caching application you already run. Do not switch it to get edge caching: in Built-in mode Magento stops sending purges to Varnish, so a Varnish that stays in front would serve stale pages.

Apply the cache rules and turn on edge caching

  1. Open System > Cloudflare > Dashboard > Health and click Apply recommended cache rules, or run bin/magento ocmlabs:cloudflare:rules:apply. You see the diff before anything is written.
  2. Under Stores > Configuration > OCMLabs > Cloudflare > Edge Cache (website scope), set Enable Edge Caching of HTML to Yes and save.
  3. Behind Varnish, purge Varnish once so pages it stored before the change are stored again with the Cloudflare header: System > Cache Management > Flush Magento Cache, or bin/magento cache:clean full_page.
  4. Click Run checks now on the Health tab. The live probes fetch a category page, the login page and a varied page through Cloudflare and report what the edge did.

To check by hand:

Terminal window
curl -sI https://www.example.com/some-category.html | grep -i cf-cache-status
curl -sI https://www.example.com/customer/account/login/ | grep -i cf-cache-status

The first should show HIT from the second request onward. The second should show DYNAMIC or BYPASS.

Grant admin access

The module registers these ACL resources under System > Permissions > User Roles:

  • OCMLabs_Cloudflare::dashboard - open the dashboard (Overview, Analytics and Health tabs)
  • OCMLabs_Cloudflare::purge - purge from the dashboard (quick purge, purge everything)
  • OCMLabs_Cloudflare::settings_write - change zone settings from the dashboard (development mode, apply cache rules, apply a health check fix)
  • OCMLabs_Cloudflare::purge_log - view the purge log
  • OCMLabs_Cloudflare::config - change module configuration under Stores > Configuration

Behind Varnish

Nothing extra is needed. Magento’s stock VCL rewrites Cache-Control to no-store, so the module also sends Cloudflare-CDN-Cache-Control, which Varnish passes through and Cloudflare caches by. Flush Magento’s cache once after turning edge caching on so Varnish stores pages with the header. See the Varnish page.

See also

In this module