Article directory
Want to run multiple on one serverWordpressWorried about cached data overwriting and front-end errors when your website has Redis object caching enabled? This tutorial provides the ultimate guide to configuring Redis across multiple WordPress sites on the same server!
This tutorial teaches two methods for allocating different Redis databases (0-15) and Cache Key Salt prefix isolation by modifying wp-config.php. These methods perfectly solve data obfuscation and significantly improve the performance of high-concurrency servers. A must-have for webmasters!
A few days ago, a friend who runs an independent website complained that his two WordPress websites had been acting strangely lately. Post titles from website A kept redirecting to website B, and cached images from website B were inexplicably appearing in the comment section of website A. I immediately laughed; it's just a matter of Redis not being configured for isolation.
Think about it: many people, in an effort to save money, like to cram several WordPress websites onto the same server and use Redis for caching on all of them. The result? All websites default to connecting to Redis Database 0, leading to a data mess. If website A's cache key coincides with website B's cache key, that's a recipe for disaster.
To be honest, I've fallen into this trap myself. When I was building an internal knowledge base, two test environments shared a single Redis instance, resulting in caches overwriting each other. It took me ages to figure out the problem. So, I have some preliminary experience to share in this area.
The core idea to solve this problem is isolation. Each website's data stays in its own separate space, without interfering with each other. How do we achieve this isolation? There are two main approaches.

Option 1: Assign different Redis databases to different websites
The first approach, which is also my top recommendation, is to assign each website a separate Redis database. Redis has 16 databases by default, numbered from 0 to 15. You can have website A use Database 0, website B use Database 1, and so on. This is like giving each website a separate hard drive partition, ensuring physical data isolation and the cleanest data storage.
The specific steps are as follows: First, install a plugin called "Redis Object Cache" in the admin panel of each WordPress website. The developer is Till Krüss, and this plugin is the most stable and reliable. Don't enable caching yet. Then, connect to the server via FTP or SSH, locate the wp-config.php file in the root directory of each website, and add a few lines of configuration above the line "/* That's all, stop editing! Happy publishing. */".
For example, the configuration of website A:
define( 'WP_REDIS_HOST', '127.0.0.1' );
define( 'WP_REDIS_PORT', 6379 );
define( 'WP_REDIS_DATABASE', 0 ); // 用数据库0
define( 'WP_CACHE_KEY_SALT', 'site_a_' ); // 加个独立前缀,双重保险For website B, simply change the database number and prefix:
define( 'WP_REDIS_HOST', '127.0.0.1' );
define( 'WP_REDIS_PORT', 6379 );
define( 'WP_REDIS_DATABASE', 1 ); // 用数据库1
define( 'WP_CACHE_KEY_SALT', 'site_b_' ); // 前缀也要改By the way, if your Redis instance has a password, you also need to add it to the configuration for each website:
define( 'WP_REDIS_PASSWORD', '你的Redis密码' );After modifying the configuration files, return to each website.WordPress backendGo to "Settings" -> "Redis" and click "Enable Object Cache". If everything goes smoothly, the status will show "Connected". At this point, the data from the two websites is isolated.
Option 2: Use different Redis Key prefixes (Salt)
However, there's a pitfall I need to warn you about beforehand. If you have more than 16 websites, or if you're using a cloud Redis service that only provides a single database, the first approach won't work. In that case, you'll need to use the second approach: using different Redis Key prefixes (Salt).
This approach allows all websites to share the same Redis database, but distinguishes data using a unique prefix. In simpler terms, it's like everyone living in the same building, but each apartment has a unique address, preventing delivery drivers from making mistakes.
The configuration method is similar, also involving adding configuration in wp-config.php, but the key is that WP_CACHE_KEY_SALT must be unique, while WP_REDIS_DATABASE can be the same (or left blank, the default is 0).
Website A's configuration:
define( 'WP_REDIS_HOST', '127.0.0.1' );
define( 'WP_REDIS_DATABASE', 0 );
define( 'WP_CACHE_KEY_SALT', 'www_siteA_com_' ); // 确保唯一Website B's configuration:
define( 'WP_REDIS_HOST', '127.0.0.1' );
define( 'WP_REDIS_DATABASE', 0 );
define( 'WP_CACHE_KEY_SALT', 'www_siteB_com_' ); // 确保唯一After configuring, simply enable caching in the plugin backend.
Common Redis Configuration Issues and Solutions
However, I must frankly say that while the second option is flexible, it carries a potential risk. If your plugin clears the entire Database 0 when clearing the cache, data from other websites might be mistakenly affected. Therefore, if you have 16 or fewer websites, I strongly recommend using the first option for greater security.
During the configuration process, you may encounter some issues. For example, the website may display errors or a blank screen after making configuration changes. In such cases, first check the code syntax in wp-config.php to see if any commas or semicolons are missing. Additionally, ensure that the PHP Redis extension (php-redis) is installed on the server; if not, install it first.
Another common question is: how do I clear the cache of a specific website? Simply click "Flush Cache" in the WordPress admin panel of each website. If you're using the first method (different databases), it will only clear the database corresponding to the current website and won't affect other websites. If you're using the second method (same database, different prefixes), some plugins might clear the entire Database 0 during the flush process, so the first method is recommended for multiple sites.
Configuring Redis is actually like charging multiple phones. You can use an individual charger for each phone (Option 1), or you can use a power strip with an independent switch for each cable (Option 2). The core principle is to ensure charging safety and prevent short circuits.
I remember when I first started setting up multiple sites, I thought configuring Redis was simple—just changing a few parameters, right? But when it actually went into production, all sorts of caching problems popped up. I later realized that technical details are often hidden in those "seemingly simple" places.
Looking back now, the configuration process itself wasn't complicated, but the underlying concept of isolation was crucial. In system design, isolation is key to ensuring stability. Just like urban planning, residential areas, industrial areas, and commercial areas must be separated, otherwise chaos will ensue.
The same applies to technical configuration. Each website should have its own independent space, without interfering with others. This is not just a technical issue, but also a design principle.哲学.
Since you've read this far, if you found it helpful, please like and share it. If you want to receive updates first, you can also follow me!
Thank you for reading my article. See you next time.
Hope Chen Weiliang Blog ( https://www.chenweiliang.com/ The article "How to Configure Redis for Multiple WordPress Websites on the Same Server? The Ultimate Tutorial to Avoid Data Obfuscation," shared here, may be helpful to you.
Welcome to share the link of this article:https://www.chenweiliang.com/cwl-34366.html
