Install and configure Redis Cache on WordPress in few steps, with Redis Object Cache and Redis open source software famous for performance and flexibility in data storage.
What is Redis Object Cache
Redis Object Cache is a WordPress plugin that implements an object caching system thanks to Redis. Supports Predis, PhpRedis (PECL), Relay, replication, sentinels, clustering and WP-CLI.
There is a paid version of the Redis Object Cache Pro plugin that is even better performing, but the free version is still sufficient to optimize the performance of your WordPress site.
Install Redis Cache on WordPress
First of all you need to make sure you have Redis installed on your server, you can follow our guide on how to install and configure Redis on Linux Ubuntu or check if your hosting provides this service typically as an add-on module for PHP.
Then you can install the plugin by downloading it from the WordPress plugin directory and directly through your site’s installation interface.
Configure Redis Cache on WordPress
Next step is to put the Redis Cache configurations at the top of the WordPress configuration file, the wp-config.php:
/** * Object Cache Config */ define( 'WP_CACHE_KEY_SALT', 'MYSITECOM:' ); define( 'WP_REDIS_HOST', 'MYREDISHOST' ); // default '127.0.0.1' define( 'WP_REDIS_PORT', MYREDISPORT ); // default 6379 define( 'WP_REDIS_PASSWORD', 'MYREDISPSWD' ); // change the database for each site to avoid cache data collisions define( 'WP_REDIS_DATABASE', MYREDISDB ); // default 0 // automatically delete cache keys after 1 days define( 'WP_REDIS_MAXTTL', 60 * 60 * 24 * 1 );
where the variables should be replaced with
- ‘MYSITECOM:’: replace with a string that identifies your site within the server, the domain name ‘mysitecom:’ could be an example
- ‘MYREDISHOST’: replace with the IP address of the Redis Host, normally it is ‘127.0.0.1’
- ‘MYREDISPORT’: replace the default Redis port, normally it is 6379
- ‘MYREDISPSWD’: replace with Redis security password.
- MYREDISDB: replace with a number from 1 to 16 to distinguish databases within the server, normally it is 0