WP CLI interface for WP Rocket
What is the WP Rocket CLI?
It’s an extension for the WP-CLI, that allows you to:
- Handle common WP Rocket functions, e.g. cache clearing, preloading, etc, using the command line.
- Automate repetitive manual tasks by using WP-CLI-driven scripts.
Prerequisites
- SSH access to your server - ask your host about this.
- WP-CLI - to install WP-CLI follow the instructions on the official page:
https://wp-cli.org/#installing - Basic knowledge of using the terminal.
WP Rocket CLI Installation
WP-CLI v0.23.0 or later
In the command line enter the following:
wp package install wp-media/wp-rocket-cli:trunk
If all goes well, you’ll see:
WP-CLI prior to v0.23.0 - Manual installation
- Download the package from here:
https://github.com/wp-media/wp-rocket-cli/archive/trunk.zip - Upload the file to your server.
- Using the command line, navigate to the folder you uploaded the file in step 1.
- Run the following command:
wp package install wp-rocket-cli-trunk.zip
Available commands
To see the list of available commands type:
wp rocket
The following will be echoed:
To learn more about the usage of a specific command and the available flags, e.g. clean, type:
wp help rocket clean
wp rocket activate-cache --htaccess=<true|false> Sets the WP_CACHE constant to true and clear WP Rocket’s cache. To update the htaccess on Apache/LiteSpeed, use the optional --htaccess flag. |
wp rocket deactivate-cache --htaccess=<true|false> Sets the WP_CACHE constant to false and clear WP Rocket’s cache. To update the htaccess on Apache/LiteSpeed, use the optional --htaccess flag. |
wp rocket clean --post_id=<post_id> --permalink=<permalink> --lang=<lang> --blog_id=<blog_id> Purge the cache of:
|
wp rocket clean --confirm Purge the whole cache without prompting for confirmation (useful for automation tools/scripts). Additionally, if the Preload feature is active, full cache preloading will start. |
wp rocket preload Preload cache files. |
wp rocket regenerate --file=<file> Regenerate the .htaccess , advanced-cache.php , or WP Rocket’s config file (/wp-content/wp-rocket-config/ folder) |
wp rocket regenerate --file=config --nginx=true Regenerate the config file on Nginx hosts. |
wp rocket cdn --enable=<enable> --host=<host> --zone=<zone> Enable / Disable the CDN with the specified host and zone. |
wp rocket export Export WP Rocket’s settings. |
wp rocket import [--file=<file>] Import WP Rocket’s settings. |
Usage examples
Using your terminal navigate in the root folder of your WordPress installation, and type the command that corresponds to the action you’d like to be performed.
Clear the whole cache
wp rocket clean
At the prompt, type y
to confirm cache clearing.
If you want to clear the cache without confirmation, append the --confirm
flag.
wp rocket clean --confirm
Note that this command will not clear the cache for Varnish.
Export WP Rocket settings
wp rocket export
Import WP Rocket settings
wp rocket import --file=wp-rocket-settings-2021-03-15-604ed873558a0.json
Alternatively, the settings file can be imported from a URL:
wp rocket import --file=https://example.com/wp-rocket-settings.json
Info & code
You can find the code for the WP Rocket CLI in our GitHub repository:
https://github.com/wp-media/wp-rocket-cli
Troubleshooting
WP-CLI ran out of memory
If you come across memory issues during installation you can either change the memory_limit
in the php.ini
or do the change "on the fly":
php -d memory_limit=512M "$(which wp)" package install wp-media/wp-rocket-cli