Magento 2 Cloudflare Extension

November 28, 2018
October 7, 2021
Rafael Grigorian

About

As a CDN Technology Partner, Cloudflare brings security and acceleration enhancements to the JetRails Hosting Platform. We picked the most relevant features for online merchants and built them directly into your Magento Administrator Control Panel. Control and modify these powerful features without leaving your store’s admin portal: Global CDN Passthrough, DDoS Mitigation, Cache Purge, JS Minification and Image Optimization, and many more. This extension supports both Magento 2 Open Source (CE) and Adobe Commerce (EE). This extension was also built for Magento 1.

Disclaimer: All product and company names are trademarks™ or registered® trademarks of their respective holders. Use of them does not imply any affiliation with or endorsement by them. Cloudflare® and their logo are trademarks of Cloudflare. Magento® and their logo are trademarks of Magento.

The MIT license

The JetRails Magento 2 extension for Cloudflare is licensed under the MIT license. If you would like to learn more, please see the details of the MIT license.

Installation process

The installation process that we will be outlining assumes that you obtained the extension through the Magento Marketplace. You can find this extension here. First, make sure you purchase it through the marketplace (it’s free). Next you will want to obtain your Magento account’s credentials to access repo.magento.com. You can find them by going to https://marketplace.magento.com/customer/accessKeys after you already signed into your magento account.

Next you will want to run the following commands:

$ composer require jetrails/magento2-cloudflare
$ php bin/magento setup:upgrade
$ php bin/magento cache:flush

Note: An additional step of logging out of your Magento backend may be required in order to refresh any altered ACL resources that the newly installed extension could have caused.

Setup process

Once the extension is installed, the Cloudflare dashboard can be found in Magento’s backend with the use of the menu by navigating to JetRails > Cloudflare Dashboard.

accessing the module

There you will be greeted with a configuration form which will look similar to the one found below.

initial configuration page

In order for this extension to work, access to Cloudflare’s API must be configured. The text box labeled Zone ID should contain the store view’s domain name’s zone id. This can be found in Cloudflare’s dashboard.

The text box labeled API Token should contain an API token that is pre-configured with Cloudflare’s Token API. For more information about creating an API Token, please refer to Cloudflare’s documentation. See image below for recommended configuration.

Note: These credentials are not the Account API Key that is found on the same page below the API Token section.

cloudflare token api config

Using the dashboard

The Cloudflare dashboard can be found by navigating to JetRails > Cloudflare Dashboard with the use of the menu in the Magento backend.

accessing the module

Assuming that the steps in the setup process were completed, you will be greeted with an array of tabs on the left side of the page. Otherwise, you will only be able to see the Overview tab, in which case you should go through the proper steps to setup the extension. This extension mimics as much functionality from Cloudflare as it can with more features and sections on their way.

cloudflare dashboard

Multi-store support

Our extension supports multi-store setups within Magento. While on the Cloudflare dashboard page, the currently selected domain name will be present to the right of the JetRails logo. When hovering over the domain name, there will be a drop down populated with all the domain names that are present in your Magento setup. By simply clicking on the domain name you want to use, you will be able to change the scope of the dashboard to configure settings related to said domain name. Please note that this implies that setup for the new domain name is required. A new set of credentials including a zone id and an API token will need to be supplied.

cloudflare dashboard

Restrict access using ACLs

Every card like section found under every tab of the Cloudflare Dashboard is assigned it’s own resource within the Magento ACL system. This means that permission to view and use every card like section can be delegated separately based on which role a user is assigned. An example case where this would be useful is if one had a developer role within the Magento ACL system and they wanted their developer to have permission to only toggle Developer Mode which lives under the Caching tab. The store administrator can simply achieve this by going to System > Permissions > User Roles.

user roles

They can then click on the developer role to edit it.

displaying all roles

Once on the edit page, they can go to Role Resources and select the JetRails > Cloudflare Dashboard > Caching > Development Mode resource.

editing role

This will give all users that are assigned to that role the permission to use the Development Mode section, while restricting access to all other sections.

CLI commands

One can save Cloudflare credentials through Magento’s CLI interface. If you run the cloudflare:set-auth command with the required options --domain, --zone, and --token then it will save the passed credentials for that passed domain. Please note that these credentials are not verified and are simply set via this command. Please login to the admin backend to verify if the saved credentials can be used.

The domain name that is passed must be one that is setup within your Magento installation. If an invalid one is passed, then all currently configured domains will be displayed to the user with an error message.

Once your credentials are saved, you have access to more helpful commands. You can always find more information about a command by passing the -h flag along side it. The following commands are implemented:

CommandDescription
cloudflare:set-authSave Cloudflare zone-id/api-token for given domain name
cloudflare:caching:development-mode:getIs site currently in development mode?
cloudflare:caching:development-mode:setSet development mode to ‘on’ or ‘off’
cloudflare:caching:purge-cache:everythingPurge all Cloudflare cache
cloudflare:caching:purge-cache:urlPurge individual URL from Cloudflare cache
cloudflare:caching:purge-cache:hostPurge hosts from Cloudflare cache
cloudflare:caching:purge-cache:prefixPurge prefixes from Cloudflare cache
cloudflare:caching:purge-cache:tagPurge tags from Cloudflare cache

Additional support

For additional support or inquiries, please feel free to reach out to us by phone or email. Any found bugs or feature requests can also be communicated to us through email. Any and all feedback would be extremely valuable and appreciated.

Call us at 1(888) 997-2457 or send an email to [email protected].