This comprehensive guide will walk you through the entire process of setting up CloudFlare R2 to work with the FluentCommunity Plugin. We’ll cover how to create and configure an R2 bucket, generate API tokens, and set up the plugin’s settings.
Steps to Configure CloudFlare R2 #
Step 1: Create a CloudFlare R2 Bucket #
- Log in to Your CloudFlare Account:
- Head over to the CloudFlare Dashboard and log in.
- Navigate to R2 Storage:
- Once logged in, find R2 under the Storage section in the left-hand sidebar.
- Create a New Bucket:
- Click the Create Bucket button.
- Choose a Unique Name: Enter a name for your bucket that is easy to identify and unique across your projects.
- Select a Location: Choose the region closest to your primary audience to minimize latency. If unsure, you can opt for Automatic to let CloudFlare select the best region for you.
- Default Storage Class: Leave it as Default unless you have specific storage requirements.
- Confirm and Create:
- Double-check your settings and click Create Bucket. Your R2 bucket is now set up and ready to be used.
Now here you will be able to see the Bucket Details. Copy the required credentials from here for later use.
Scroll down for the R2.dev subdomain section on this page and here you will get R2.dev Bucket URL. Also, you need to Allow Access to this R2.dev subdomain.
Click on the Allow Access button to allow.
Step 2: Generate API Tokens #
- Access Your Profile Settings:
- In the CloudFlare dashboard, click on your profile icon at the top right corner and select My Profile.
- From your profile settings, click on API Tokens. Here, you can create a custom API token with the necessary permissions.
- Create a New API Token:
- Click the Get Started button from the Custom Token section.
- Click the Create Token button.
- Configure Token Permissions:
- Under Permissions, set the following:
- Account > Workers R2 Storage > Edit
- Account Resources: Choose your specific account to limit the token’s access scope.
- Under Permissions, set the following:
- Generate and Save the Token:
- Click Create Token and make sure to securely copy and store both the Access Key and Secret Key displayed. You won’t be able to view them again once you leave this screen.
Step 3: Obtain Your R2 Endpoint #
- Locate the R2 API Endpoint:
- Go to R2 in the CloudFlare dashboard and click on Overview.
- In the R2 API section, you’ll find the Endpoint URL. Copy this URL, which usually looks something like https://<ACCOUNT_ID>.r2.cloudflarestorage.com.
Step 4: Configure FluentCommunity Plugin #
- Access Plugin Settings in WordPress:
- Navigate to FluentCommunity Plugin > Settings > Features & Addons.
- Scroll down to locate the Media Module section and click on the Configure button. Now select Cloudflare R2.
- Input Your CloudFlare Credentials:
- Access Key: Paste the Access Key you saved earlier from your CloudFlare API token.
- Secret Key: Enter the Secret Key from your CloudFlare API token.
- Account ID: Input your CloudFlare Account ID (find this in your CloudFlare dashboard under your account settings).
- Bucket: Enter the name of the R2 bucket you created in Step 1.
- Sub Folder (Optional): If you’d like to organize files within a specific subfolder in your bucket, specify the subfolder name here.
- Public URL: Provide the public URL for your R2 bucket. It typically looks like https://pub-<ACCOUNT_ID>.r2.dev.
- Save Your Settings:
- Once all fields are filled in correctly, click the Save button to store your configuration.
Additional Configuration (Optional) #
For more advanced setups, you can define your CloudFlare R2 settings in your wp-config.php file. This method provides an extra layer of security and is useful for managing configurations across different environments.
Add These Lines to wp-config.php: #
php
Copy code
// CloudFlare R2 Configuration
define('FLUENT_COMMUNITY_CLOUD_STORAGE', 'cloudflare_r2');
define('FLUENT_COMMUNITY_CLOUD_STORAGE_ACCOUNT_ID', 'YOUR_ACCOUNT_ID'); // Example: 1718cb5a51e65c8f19e8sahdakh763
define('FLUENT_COMMUNITY_CLOUD_STORAGE_ACCESS_KEY', 'YOUR_ACCESS_KEY');
define('FLUENT_COMMUNITY_CLOUD_STORAGE_SECRET_KEY', 'YOUR_SECRET_KEY');
define('FLUENT_COMMUNITY_CLOUD_STORAGE_BUCKET', 'YOUR_BUCKET_NAME');
define('FLUENT_COMMUNITY_CLOUD_STORAGE_PUBLIC_URL', 'https://pub-SOME_RANDOM_STRINGS.r2.dev'); // Custom domain if configured
define('FLUENT_COMMUNITY_CLOUD_STORAGE_SUB_FOLDER', 'your-subfolder-name'); // Optional
Note: Defining these values in wp-config.php will override any settings configured in the FluentCommunity plugin’s admin panel.
Troubleshooting Common Issues #
- API Token Permissions: Ensure your API token has the correct permissions for R2 access.
- Incorrect Bucket or URL: Double-check that your bucket name and public URL are accurate and correctly configured.
- Custom Domain Setup: If using a custom domain, confirm it is properly configured in CloudFlare to avoid connectivity issues.
For any additional support, feel free to reach out to our support team. We’re here to assist you!