How to use WP Rocket with Bedrock WordPress Boilerplate
Heads Up! This tutorial is very specific and dedicated to experienced developers. If you are not familiar with Bedrock it's because you are not using it. In this case, you can safely skip reading this article.
Bedrock is an open source project by Roots and a modern WordPress stack: it's a very useful tool to configure and manage your WordPress and it includes several development tools.
To learn how to use WP Rocket on Bedrock you can follow the steps described in our blog post: How to Set Up WP Rocket on Trellis and Bedrock.
License validation
To validate your license you'll need to:
- Add the following in the
.env
file: - Add the following code in the
/config/application.php
file:
// WP Rocket's API key if ( env( 'WP_ROCKET_KEY' ) ) { define( 'WP_ROCKET_KEY', env( 'WP_ROCKET_KEY' ) ); } // WP Rocket registration email if ( env( 'WP_ROCKET_EMAIL' ) ) { define( 'WP_ROCKET_EMAIL', env( 'WP_ROCKET_EMAIL' ) ); }
WP_ROCKET_KEY='your_license_key' WP_ROCKET_EMAIL='your_registration_email'
Replace "your_license_key" and "your_registration_email" with the info you'll find in the licence-data.php
file in WP Rocket's installation ZIP:
Having issues with the WP_CACHE constant added into wp-config.php?
You can use our filter rocket_set_wp_cache_constant. This filter prevents WP Rocket from adding this line at the top of wp-config.php file upon activation:
define( 'WP_CACHE', true ); // Added by WP Rocket
To use the filter, you can add this line to the theme's functions.php file:
add_filter( 'rocket_set_wp_cache_constant', '__return_false' );
⛔️ Deprecated: The following content covers a deprecated version of Bedrock.
If you still use this version, you might want to consider updating to a recent version of Bedrock.
In this doc we'll explain you how to run WP Rocket with a Bedrock-Capistrano setup.
There is another way to deploy Bedrock, Trellis, which is not covered in this tutorial.
- 1
-
Create a static advanced-cache.php and commit it to your website's Git repo.
Note: The following code is just an example. You should add your own path to this code. The exact paths are dependent on the environment within which your website is running.
<?php defined( 'ABSPATH' ) or die( 'Cheatin\' uh?' ) ; define( 'WP_ROCKET_ADVANCED_CACHE' , true ) ; $root_path = WP_ENV == 'development' ? '/Users/yourlocalfolder/yoursite.local' : '/usr/share/nginx/www/current' ; $rocket_cache_path = $root_path . '/web/app/cache/wp-rocket/' ; $rocket_config_path = $root_path . '/web/app/wp-rocket-config/' ; if ( file_exists( $root_path . '/web/app/plugins/wp-rocket/inc/front/process.php' ) ) { include( $root_path . '/web/app/plugins/wp-rocket/inc/front/process.php' ) ; } else { define( 'WP_ROCKET_ADVANCED_CACHE_PROBLEM' , true ) ; }
- 2
-
Commit the empty /cache and /wp-rocket-config folders to the Git repo (adding their contents to your .gitignore file). These directories should be set as linked directories in your Capistrano deploy script: in this way you can maintain them across releases.
Thanks to our customer Robert Sargent for providing us with this tutorial! 🎩