{"id":1838,"date":"2026-09-05T09:24:20","date_gmt":"2026-09-05T03:54:20","guid":{"rendered":"https:\/\/cpanelfree.com\/blog\/how-to-setup-redis-object-caching-wordpress\/"},"modified":"2026-09-05T12:57:36","modified_gmt":"2026-09-05T07:27:36","slug":"how-to-setup-redis-object-caching-wordpress","status":"publish","type":"post","link":"https:\/\/cpanelfree.com\/blog\/how-to-setup-redis-object-caching-wordpress\/","title":{"rendered":"How to Set Up Redis Object Caching for WordPress on Ubuntu VPS (Sub-100ms TTFB)"},"content":{"rendered":"<h2>Why MySQL Database Queries Slow Down WordPress<\/h2>\n<p>Every time a visitor lands on a WordPress post or WooCommerce catalog page, the PHP application engine executes dozens\u2014sometimes hundreds\u2014of SQL queries to retrieve post metadata, user privileges, site options, taxonomy relationships, and active plugin settings. Under heavy traffic spikes, the MySQL\/MariaDB database becomes the primary bottleneck, causing high CPU load, connection queue timeouts, and sluggish page load speeds exceeding 1.5 seconds.<\/p>\n<p><strong>Redis (Remote Dictionary Server)<\/strong> is an ultra-fast, in-memory key-value data store. When configured as a persistent WordPress Object Cache, Redis intercepts database requests and stores the compiled query results directly in volatile RAM. Repeated queries are resolved in fractions of a millisecond, slashing database load by up to 90% and delivering a blistering Time-To-First-Byte (TTFB) well under 100 milliseconds.<\/p>\n<p>In this comprehensive optimization tutorial, we will configure Redis on Ubuntu 24.04\/22.04 LTS, secure communication using high-throughput Unix domain sockets, tune memory reclamation policies, and integrate the official Redis Object Cache plugin into WordPress.<\/p>\n<h2>Step 1: Installing Redis Server and PHP Redis Extension<\/h2>\n<p>Install the official Redis server daemon along with the native compiled <code>php-redis<\/code> extension for maximum execution efficiency:<\/p>\n<pre><code># Update package list and install Redis server\nsudo apt update &amp;&amp; sudo apt install -y redis-server php-redis\n\n# Confirm Redis service status\nsudo systemctl status redis-server --no-pager\n\n# Test Redis CLI ping response\nredis-cli ping\n# Output: PONG<\/code><\/pre>\n<h2>Step 2: Optimizing Redis Configuration for High Concurrency<\/h2>\n<p>By default, Redis communicates over TCP port <code>6379<\/code>. On a standalone VPS where WordPress and Redis reside on the same machine, switching to a Unix Domain Socket eliminates TCP network overhead and reduces CPU context switching. Edit <code>\/etc\/redis\/redis.conf<\/code>:<\/p>\n<pre><code># Disable TCP port for local-only security\nport 0\n\n# Enable high-speed Unix socket communication\nunixsocket \/var\/run\/redis\/redis-server.sock\nunixsocketperm 770\n\n# Set maximum memory allocation based on VPS RAM budget\nmaxmemory 256mb\n\n# Evict least recently used keys automatically when memory is full\nmaxmemory-policy allkeys-lru\n\n# Disable disk persistence for pure caching workload (saves SSD write cycles)\nsave \"\"\nappendonly no<\/code><\/pre>\n<p>Grant the web server user (<code>www-data<\/code>) permission to access the Redis socket and restart the service:<\/p>\n<pre><code># Add www-data user to redis group\nsudo usermod -aG redis www-data\n\n# Restart Redis daemon\nsudo systemctl restart redis-server<\/code><\/pre>\n<h2>Step 3: Configuring WordPress wp-config.php for Redis<\/h2>\n<p>Open your WordPress configuration file <code>wp-config.php<\/code> and add the Redis object cache parameters above the <code>\/* That's all, stop editing! Happy publishing. *\/<\/code> line:<\/p>\n<pre><code>\/\/ Enable Redis Persistent Object Cache\ndefine( 'WP_CACHE', true );\ndefine( 'WP_REDIS_SCHEME', 'unix' );\ndefine( 'WP_REDIS_PATH', '\/var\/run\/redis\/redis-server.sock' );\ndefine( 'WP_REDIS_TIMEOUT', 1 );\ndefine( 'WP_REDIS_READ_TIMEOUT', 1 );\n\n\/\/ Unique prefix for multi-site isolation (prevents cache collisions)\ndefine( 'WP_REDIS_PREFIX', 'cpanelfree_prod_' );\n\n\/\/ Set default cache expiration (in seconds: 1 day)\ndefine( 'WP_REDIS_MAXTTL', 86400 );<\/code><\/pre>\n<h2>Step 4: Installing and Activating Redis Object Cache via WP-CLI<\/h2>\n<p>Use WP-CLI to install the official Till Kr\u00fcss Redis Object Cache plugin and activate the drop-in <code>object-cache.php<\/code> handler:<\/p>\n<pre><code>cd \/var\/www\/html\n\n# Install and activate the plugin\nwp plugin install redis-cache --activate --allow-root\n\n# Enable the object cache drop-in\nwp redis enable --allow-root\n\n# Verify Redis connection status\nwp redis status --allow-root<\/code><\/pre>\n<h2>Step 5: Verifying Cache Hit Ratio &amp; Real-Time Telemetry<\/h2>\n<p>To confirm that WordPress is actively reading and writing to Redis rather than hitting MySQL, inspect the Redis key-space statistics in real-time:<\/p>\n<pre><code># Monitor real-time Redis commands as you browse your website\nredis-cli -s \/var\/run\/redis\/redis-server.sock monitor\n\n# Inspect total keys, hits, and misses\nredis-cli -s \/var\/run\/redis\/redis-server.sock info stats | grep -E \"(keyspace_hits|keyspace_misses)\"<\/code><\/pre>\n<h2>Performance Comparison: Standard MySQL vs Redis Object Cache<\/h2>\n<table style=\"width: 100%;border-collapse: collapse;margin: 20px 0;border: 1px solid #334155\">\n<thead>\n<tr style=\"background-color: #0f172a;color: #38bdf8\">\n<th style=\"padding: 12px;border: 1px solid #334155\">Performance Metric<\/th>\n<th style=\"padding: 12px;border: 1px solid #334155\">Standard MySQL Only<\/th>\n<th style=\"padding: 12px;border: 1px solid #334155\">Redis In-Memory Object Cache<\/th>\n<th style=\"padding: 12px;border: 1px solid #334155\">Improvement Delta<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr style=\"background-color: #1e293b;color: #f8fafc\">\n<td style=\"padding: 10px;border: 1px solid #334155\"><strong>Database Queries \/ Page<\/strong><\/td>\n<td style=\"padding: 10px;border: 1px solid #334155\">65 to 110 SQL queries<\/td>\n<td style=\"padding: 10px;border: 1px solid #334155\">4 to 8 SQL queries<\/td>\n<td style=\"padding: 10px;border: 1px solid #334155\"><strong>~92% Reduction<\/strong><\/td>\n<\/tr>\n<tr style=\"background-color: #0f172a;color: #f8fafc\">\n<td style=\"padding: 10px;border: 1px solid #334155\"><strong>Time-To-First-Byte (TTFB)<\/strong><\/td>\n<td style=\"padding: 10px;border: 1px solid #334155\">450ms \u2013 1,200ms<\/td>\n<td style=\"padding: 10px;border: 1px solid #334155\"><strong>45ms \u2013 95ms<\/strong><\/td>\n<td style=\"padding: 10px;border: 1px solid #334155\"><strong>10x Faster<\/strong><\/td>\n<\/tr>\n<tr style=\"background-color: #1e293b;color: #f8fafc\">\n<td style=\"padding: 10px;border: 1px solid #334155\"><strong>Concurrent User Capacity<\/strong><\/td>\n<td style=\"padding: 10px;border: 1px solid #334155\">~50 concurrent visitors<\/td>\n<td style=\"padding: 10px;border: 1px solid #334155\">~450+ concurrent visitors<\/td>\n<td style=\"padding: 10px;border: 1px solid #334155\"><strong>9x Scalability<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Redis Cache Maintenance Best Practices<\/h2>\n<ul>\n<li><strong>Flush Cache After Major Updates:<\/strong> When pushing major theme updates or database schema changes, flush stale cache objects via <code>wp redis flush<\/code>.<\/li>\n<li><strong>Exclude Volatile Transients:<\/strong> Keep transient sessions separate from persistent object caches if you run membership plugins with heavy session write cycles.<\/li>\n<li><strong>Monitor Linux vm.overcommit_memory:<\/strong> Ensure <code>sysctl vm.overcommit_memory=1<\/code> is set in <code>\/etc\/sysctl.conf<\/code> to prevent Redis background save failures under memory pressure.<\/li>\n<\/ul>\n<h2>Advanced Multi-Site Redis Prefixing &amp; Cluster Isolation<\/h2>\n<p>If you host multiple WordPress installations on the same Linux VPS, all sites will attempt to write to Redis using default keys. Without distinct prefix isolation, site A&#8217;s cached options will overwrite site B&#8217;s options, causing corrupted options, incorrect logins, and white screens. Always assign a unique cryptographic prefix in each site&#8217;s <code>wp-config.php<\/code>:<\/p>\n<pre><code>\/\/ Site 1 Prefix Configuration:\ndefine( 'WP_REDIS_PREFIX', 'site_primary_hash_' );\n\n\/\/ Site 2 Prefix Configuration:\ndefine( 'WP_REDIS_PREFIX', 'site_ecommerce_hash_' );<\/code><\/pre>\n<h2>Automating Redis Cache Warm-Up via WP-CLI Cron<\/h2>\n<p>After clearing the cache during content updates, priming the cache automatically ensures visitors always hit cached RAM:<\/p>\n<pre><code># Create automated cache warming script (\/usr\/local\/bin\/warm-redis-cache.sh)\n#!\/bin\/bash\nDOMAIN=\"https:\/\/cpanelfree.com\"\ncurl -s \"$DOMAIN\/sitemap.xml\" | grep -oP '(?&lt;=&lt;loc&gt;)[^&lt;]+&#039; | while read url; do\n    curl -s -o \/dev\/null -A &quot;CacheWarmerBot\/1.0&quot; &quot;$url&quot;\ndone\necho &quot;Redis cache warmed successfully!&quot;<\/code><\/pre>\n<h2>Redis Key-Space Troubleshooting &amp; Diagnostics<\/h2>\n<table style=\"width: 100%;border-collapse: collapse;margin: 20px 0;border: 1px solid #334155\">\n<thead>\n<tr style=\"background-color: #0f172a;color: #38bdf8\">\n<th style=\"padding: 12px;border: 1px solid #334155\">Issue<\/th>\n<th style=\"padding: 12px;border: 1px solid #334155\">Root Cause<\/th>\n<th style=\"padding: 12px;border: 1px solid #334155\">Fix<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr style=\"background-color: #1e293b;color: #f8fafc\">\n<td style=\"padding: 10px;border: 1px solid #334155\">Permission Denied on Redis Socket<\/td>\n<td style=\"padding: 10px;border: 1px solid #334155\"><code>www-data<\/code> user not in <code>redis<\/code> group<\/td>\n<td style=\"padding: 10px;border: 1px solid #334155\"><code>sudo usermod -aG redis www-data &amp;&amp; sudo systemctl restart php8.3-fpm<\/code><\/td>\n<\/tr>\n<tr style=\"background-color: #0f172a;color: #f8fafc\">\n<td style=\"padding: 10px;border: 1px solid #334155\">OOM command not allowed when used memory &gt; &#8216;maxmemory&#8217;<\/td>\n<td style=\"padding: 10px;border: 1px solid #334155\"><code>maxmemory-policy<\/code> not configured to evict keys<\/td>\n<td style=\"padding: 10px;border: 1px solid #334155\">Set <code>maxmemory-policy allkeys-lru<\/code> in <code>redis.conf<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div style=\"background-color: #0f172a;border-left: 4px solid #38bdf8;padding: 18px 24px;margin: 30px 0;border-radius: 8px\">\n<h3 style=\"color: #38bdf8;margin-top: 0\">Recommended Related Technical Guides<\/h3>\n<ul style=\"margin-bottom: 0;color: #cbd5e1\">\n<li><a href=\"https:\/\/cpanelfree.com\/blog\/how-to-install-wp-cli-automate-wordpress-admin-tasks\/\" style=\"color: #38bdf8;text-decoration: underline\">How to Install WP-CLI &amp; Automate WordPress Management<\/a><\/li>\n<li><a href=\"https:\/\/cpanelfree.com\/blog\/how-to-fix-502-bad-gateway-nginx-openlitespeed-php-fpm\/\" style=\"color: #38bdf8;text-decoration: underline\">Troubleshooting 502 Bad Gateway and Server Timeouts<\/a><\/li>\n<li><a href=\"https:\/\/cpanelfree.com\/blog\/how-to-install-multiple-php-versions-ubuntu\/\" style=\"color: #38bdf8;text-decoration: underline\">Configuring PHP 8.3 with OPcache on Ubuntu VPS<\/a><\/li>\n<\/ul>\n<\/div>\n<div style=\"background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);color: #ffffff;padding: 28px;border-radius: 12px;margin: 35px 0;text-align: center\">\n<h3 style=\"color: #ffffff;margin-top: 0;font-size: 22px\">Supercharge Your WordPress Speed on CpanelFree Hosting<\/h3>\n<p style=\"color: #e0f2fe;font-size: 15px;max-width: 650px;margin: 0 auto 18px auto\">Unlock enterprise NVMe storage, pre-configured Redis object caching, and 99.9% uptime with 100% free hosting and VPS accounts.<\/p>\n<p>  <a href=\"https:\/\/cpanelfree.com\/\" style=\"background-color: #ffffff;color: #0284c7;font-weight: 700;padding: 12px 28px;border-radius: 8px;text-decoration: none;display: inline-block\">Get Free High-Speed Hosting &rarr;<\/a>\n<\/div>\n<div style=\"border-left: 4px solid #38bdf8;border-radius: 8px;padding: 20px;margin: 30px 0\">\n<h3 style=\"margin-top: 0;color: #38bdf8;font-size: 18px;display: flex;align-items: center\">\n        <span style=\"margin-right: 8px\">\ud83d\udd17<\/span> Recommended Related Technical Guides:<br \/>\n    <\/h3>\n<ul style=\"margin: 10px 0 0 0;padding-left: 20px;line-height: 1.8\">\n<li><a href=\"https:\/\/cpanelfree.com\/blog\/how-to-configure-litespeed-cache-wordpress-100-pagespeed\/\" style=\"color: #38bdf8;text-decoration: none;font-weight: 600\">How to Configure LiteSpeed Cache (LSCache) for 100\/100 Google PageSpeed Score<\/a><\/li>\n<li><a href=\"https:\/\/cpanelfree.com\/blog\/redis-vs-memcached-wordpress-cache-benchmark\/\" style=\"color: #38bdf8;text-decoration: none;font-weight: 600\">Redis Object Cache vs Memcached: Which is Faster for High-Traffic WordPress?<\/a><\/li>\n<li><a href=\"https:\/\/cpanelfree.com\/blog\/how-to-convert-serve-webp-avif-images-wordpress\/\" style=\"color: #38bdf8;text-decoration: none;font-weight: 600\">How to Automatically Convert and Serve WebP &amp; AVIF Images in WordPress<\/a><\/li>\n<li><a href=\"https:\/\/cpanelfree.com\/blog\/how-to-get-free-domain-with-free-hosting\/\" style=\"color: #38bdf8;text-decoration: none;font-weight: 600\">How to Get a 100% Free Domain Name with Free Web Hosting (2026)<\/a><\/li>\n<li><a href=\"https:\/\/cpanelfree.com\/#plans\" style=\"color: #10b981;text-decoration: none;font-weight: 600\">Explore $0 Free cPanel Web Hosting Plans (NVMe SSD, AutoSSL)<\/a><\/li>\n<\/ul>\n<\/div>\n<div style=\"background: linear-gradient(135deg, rgba(6, 182, 212, 0.15) 0%, rgba(59, 130, 246, 0.15) 100%);border-radius: 12px;padding: 25px;margin: 30px 0;text-align: center\">\n<h3 style=\"color: #38bdf8;margin-top: 0;font-size: 20px\">Deploy Fast, Reliable Web Hosting on CpanelFree<\/h3>\n<p style=\"color: #94a3b8;font-size: 14px;line-height: 1.6;max-width: 600px;margin: 0 auto 15px\">\n        Get genuine cPanel control, unmetered NVMe SSD storage, and free AutoSSL at $0 cost forever.\n    <\/p>\n<p>    <a href=\"https:\/\/cpanelfree.com\/#plans\" style=\"display: inline-block;background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);color: #ffffff;padding: 10px 22px;border-radius: 6px;text-decoration: none;font-weight: bold;font-size: 14px\">Claim Free Hosting Account<\/a>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Why MySQL Database Queries Slow Down WordPress Every time a visitor lands on a WordPress post or WooCommerce catalog page, the PHP application engine executes dozens\u2014sometimes hundreds\u2014of SQL queries to retrieve post metadata, user privileges, site options, taxonomy relationships, and active plugin settings. Under heavy traffic spikes, the MySQL\/MariaDB database becomes the primary bottleneck, causing [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2491,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[161],"tags":[],"class_list":["post-1838","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-optimization"],"_links":{"self":[{"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/posts\/1838","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/comments?post=1838"}],"version-history":[{"count":2,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/posts\/1838\/revisions"}],"predecessor-version":[{"id":2291,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/posts\/1838\/revisions\/2291"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/media\/2491"}],"wp:attachment":[{"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/media?parent=1838"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/categories?post=1838"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/tags?post=1838"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}