How to Deploy WordPress on SharkCluster with Redis and Varnish Caching
Back to the blog
How-To / WordPress

How to Deploy WordPress on SharkCluster with Redis and Varnish Caching

SharkClusterSharkCluster TeamNovember 30, 20268 min read

A fresh WordPress site is quick when it has ten posts and no visitors. Add WooCommerce, a page builder, a dozen plugins and real traffic, and every page view becomes PHP execution plus a stack of database queries. Time to first byte climbs, the server's CPU stays busy, and a traffic spike can take the site down.

Caching fixes most of this. This guide shows how to deploy WordPress on SharkCluster and then add two layers of cache: Redis for database query results (the WordPress object cache) and Varnish for full pages. Together with OPcache, which is already on, they let the server answer most requests without running WordPress at all.

How to Deploy WordPress on SharkCluster with Redis and Varnish Caching

How the three caching layers fit together

LayerWhat it cachesWho benefits
VarnishComplete HTML pages, in memory, in front of the web serverAnonymous visitors: blog readers, product page browsers, search engine crawlers
Redis object cacheResults of database queries and expensive lookupsEveryone, including logged-in users, wp-admin and WooCommerce cart/checkout
OPcacheCompiled PHP codeEvery PHP request

Varnish gives the biggest speed-up, but only for pages that are the same for every visitor. Redis covers what Varnish can't: logged-in sessions, the admin area, carts and checkout. Use both.

With Varnish in place, a request flows like this:

text
Visitor
  → NGINX or Apache on ports 80/443 (handles HTTPS)
  → Varnish (serves the page from memory if it has it)
  → Web server on a backend port → PHP-FPM → WordPress → MySQL
                                            ↘ Redis (object cache)

Step 1: Create a server

Go to Servers → Create Server, pick DigitalOcean, Contabo or OVHcloud, choose the region closest to your visitors and select a plan. For a business site or a small WooCommerce store, 2 vCPU and 4 GB RAM is a comfortable start; Redis and Varnish both use memory, so leave room for them. You can resize later.

SharkCluster Create Server screen with provider, region and plan selection
SharkCluster Create Server screen with provider, region and plan selection

Step 2: Deploy WordPress

Open the server, go to Applications and click Create Application. Then:

  1. Application name. A name you'll recognise, for example company-site.
  2. Choose webserver. NGINX or Apache. Choose Apache if your plugins rely on .htaccess rules (many security and redirect plugins do); NGINX otherwise.
  3. Select application type. Open the CMS & E-commerce tab and select WordPress.
  4. Database. MySQL (default) or MariaDB. SharkCluster creates the database, user and password and wires them into WordPress for you.
  5. How to set up the application. Fresh Installation for a new site. If you're moving an existing site, use Deploy from Git Repo or Upload ZIP; both let you pick the PHP version your code needs.
  6. Automated backups. Choose daily or weekly and the time they run.

Check the summary and click Create Application. The installation page shows progress while the stack is set up.

Create Application form with WordPress selected under CMS & E-commerce, NGINX chosen as the web server and MySQL as the database
Create Application form with WordPress selected under CMS & E-commerce, NGINX chosen as the web server and MySQL as the database

Every PHP application runs in its own PHP-FPM pool, so one busy site doesn't slow down the others on the same server. SharkCluster doesn't charge per site, so you can run many client sites on one server.

Step 3: Add your domain and free SSL

Open the application and go to Domains → Add domain:

  1. Enter your domain, for example example.com.
  2. Keep Automatic HTTPS & SSL on for a free Let's Encrypt certificate that renews automatically. Choose whether visitors land on the www or non-www version; the other gets a 301 redirect.
  3. Add the A record shown under Required DNS Records at your DNS provider, click Check DNS and then Save Domain.

DNS usually propagates in 2 to 30 minutes, after which the certificate is issued. The step-by-step version is in how to add a domain to your application, and if you use Cloudflare, see how to integrate Cloudflare.

WordPress stores its site URL in the database. If you installed it before adding the domain, update WordPress Address and Site Address under Settings → General in wp-admin to the new https:// address.

Step 4: Log in to wp-admin

The administrator account is created during installation. Open the application's Access tab: the Admin Login section shows the admin panel URL, the username and the password, with a button to open the login page.

Application Access tab showing the Admin Login section with admin panel URL, username and masked password
Application Access tab showing the Admin Login section with admin panel URL, username and masked password

Change the password after your first login and create named accounts for anyone else who needs access.

Step 5: Install Redis and turn on the object cache

Install Redis on the server

Go to the server's Packages page, open the Browse tab, filter by Caching (or search for redis) and click Install on Redis. It moves to the Installed tab with its status, version and port when it's ready.

Packages page, Browse tab filtered to Caching, with the Install button on Redis
Packages page, Browse tab filtered to Caching, with the Install button on Redis

Redis listens on 127.0.0.1:6379 only, so it isn't reachable from the internet. From Details & Config you can change the idle timeout and maximum connections, and read Redis logs.

Set a memory limit

Give Redis a memory ceiling and an eviction policy so a full cache drops old keys instead of growing without limit. Open the web console (application Security → Access) or SSH in and edit /etc/redis/redis.conf:

text
maxmemory 256mb
maxmemory-policy allkeys-lru
bash
sudo systemctl restart redis-server

256 MB is plenty for most single sites. Increase it for large WooCommerce catalogues or when several sites share the server.

Connect WordPress to Redis

In wp-admin, go to Plugins → Add New, install and activate Redis Object Cache (by Till Krüss). Then add these lines to wp-config.php above the line that says /* That's all, stop editing! */. You can edit the file from the application's File Manager:

php
define( 'WP_REDIS_HOST', '127.0.0.1' );
define( 'WP_REDIS_PORT', 6379 );
define( 'WP_REDIS_PREFIX', 'company-site:' );   // unique per site
define( 'WP_CACHE_KEY_SALT', 'company-site:' );

Use a unique prefix for each WordPress site on the server. Redis is shared by every application on the server, so two sites without separate prefixes can read each other's cached data.

Back in wp-admin, open Settings → Redis and click Enable Object Cache. The status should change to Connected.

Step 6: Install Varnish and put it in front of WordPress

Install Varnish

On the same Packages → Browse page, filter by Caching and install Varnish Cache.

Installing Varnish doesn't route traffic through it yet. A fresh install listens on port 6081 and expects the web server on a backend port, while NGINX or Apache keeps serving your site on 80/443. To place Varnish in front of the site, click Request Setup at the bottom of the Browse tab (or contact support) and the SharkCluster team will reconfigure the web server for you. Your web server continues to handle HTTPS, because Varnish doesn't speak TLS.

Packages page showing Varnish Cache on the Installed tab and the Request Setup banner
Packages page showing Varnish Cache on the Installed tab and the Request Setup banner

Use a WordPress-safe VCL

Varnish's rules live in /etc/varnish/default.vcl. The most important rule for WordPress is never cache pages for logged-in users, or one visitor could see another's account page or cart. Ask for a WordPress VCL during setup, or apply one yourself. A minimal version:

text
vcl 4.1;

backend default {
    .host = "127.0.0.1";
    .port = "8080";
}

acl purge {
    "127.0.0.1";
    "localhost";
}

sub vcl_recv {
    # Allow purge requests from the server itself (cache purge plugin)
    if (req.method == "PURGE") {
        if (!client.ip ~ purge) { return (synth(405, "Not allowed")); }
        return (purge);
    }

    # Only cache GET and HEAD
    if (req.method != "GET" && req.method != "HEAD") { return (pass); }

    # Never cache admin, login, cron, REST API or WooCommerce pages
    if (req.url ~ "^/(wp-admin|wp-login\.php|wp-cron\.php|wp-json|xmlrpc\.php)" ||
        req.url ~ "^/(cart|checkout|my-account)" ||
        req.url ~ "(\?|&)(add-to-cart|wc-ajax)=") {
        return (pass);
    }

    # Never cache logged-in users, commenters or visitors with a cart
    if (req.http.Cookie ~ "wordpress_logged_in_|wordpress_sec_|wp-postpass_|comment_author_|woocommerce_items_in_cart|wp_woocommerce_session_") {
        return (pass);
    }

    # Everyone else: drop cookies so the page can be cached
    unset req.http.Cookie;
    return (hash);
}

sub vcl_backend_response {
    # Cache pages for 1 hour; serve stale content for up to 6 hours if PHP is slow or down
    if (bereq.url !~ "^/(wp-admin|wp-login\.php|cart|checkout|my-account)") {
        unset beresp.http.Set-Cookie;
        set beresp.ttl = 1h;
        set beresp.grace = 6h;
    }
}

Set the backend port to the one your web server listens on after setup. Check the file and reload Varnish without dropping the cache:

bash
sudo varnishd -C -f /etc/varnish/default.vcl > /dev/null && echo "VCL OK"
sudo systemctl reload varnish

If users ever report seeing someone else's account or cart, logged-in pages are being cached. Stop Varnish from the Installed tab or restore the previous VCL immediately, then fix the cookie rules.

Purge the cache when content changes

With a one-hour TTL, edits can take up to an hour to show. Install the Proxy Cache Purge plugin in WordPress: it sends a PURGE request for the affected pages whenever you publish or update a post, and the acl purge block above allows those requests from the server itself.

To clear everything by hand, run this in the web console:

bash
# Clear the whole cache
sudo varnishadm "ban req.url ~ ."

# Clear one section, e.g. the blog
sudo varnishadm "ban req.url ~ ^/blog"

Restarting Varnish also empties the cache.

Step 7: Check that caching works

Request a page twice as an anonymous visitor and look at the response headers:

bash
curl -sI https://example.com/ | grep -iE "^(age|x-varnish|via)"

Age above 0 on the second request and two numbers in X-Varnish mean the page came from the cache. Then log in to wp-admin and confirm admin pages are not cached (Age stays at 0).

For Redis, the Settings → Redis screen in wp-admin shows the connection status and cache metrics. Watch CPU and response times on the application's Analytics page and the server's monitoring graphs: with both caches in place, CPU on a busy site should drop noticeably.

Troubleshooting

SymptomLikely causeFix
503 Backend fetch failedVarnish can't reach the web serverCheck the backend host and port in default.vcl match the web server's backend port, and that the web server is running
Changes don't appear on the siteThe old page is still cachedCheck that Proxy Cache Purge is active, or ban the URL with varnishadm
Users see another user's cart or accountLogged-in pages are being cachedStop Varnish or restore the previous VCL, then fix the cookie pass rules
Redis Object Cache shows Not connectedRedis isn't running or the host/port is wrongCheck Redis on the Installed tab and the WP_REDIS_HOST and WP_REDIS_PORT values
Two sites show each other's dataShared Redis without unique prefixesSet a different WP_REDIS_PREFIX and WP_CACHE_KEY_SALT on each site, then flush the object cache

FAQ

Do I need both Redis and Varnish?

Small brochure sites do well with Varnish alone. Anything with logged-in users, WooCommerce or a busy admin area benefits from Redis too, because Varnish passes those requests straight to WordPress.

Does Varnish work with WooCommerce?

Yes, as long as cart, checkout and account pages, and visitors with a cart cookie, bypass the cache. The VCL above does that.

Is SSL affected by Varnish?

No. NGINX or Apache still terminates HTTPS on port 443 with your free Let's Encrypt certificate, then hands the request to Varnish.

Can I use a caching plugin like WP Rocket as well?

You can, but disable its page cache to avoid caching the same page twice; keep its file optimisation features if you like them. Varnish handles page caching more efficiently in memory.

Next steps

Your WordPress site now runs on your own server with HTTPS, an object cache and a page cache. To go further, see 5 ways to optimize application performance on SharkCluster, the caching feature overview and SharkCluster for ecommerce. If you're moving an existing site, migrations are free: raise a ticket and the team will move it for you.

Share this article
Share

Run this on your own VPS

Deploy servers and applications on infrastructure you own, managed from one panel — backups, caching, firewall and monitoring included.

Start your journey today

How do you start
with SharkCluster?

To start with SharkCluster, create an account and your first server on DigitalOcean, Contabo or OVHcloud — no credit card or lock-in contract is needed. Every account includes free self-hosted business apps, free local backups, unlimited migrations and a dedicated DevOps manager.

No lock-in contracts
No credit card required
Dedicated DevOps manager