A fast website is essential in e-commerce: it improves the user experience, reduces bounce rates and increases the conversion rate. In this context, Varnish Cache is one of the most powerful tools to drastically improve the loading times of your Shopware 6.6 store.
In this article, we’ll show you exactly what Varnish does, how to set it up on a Linux server with Shopware 6.6, which before and after performance comparisons are possible – as well as typical pitfalls and their solutions.
What exactly does Varnish do?
Varnish Cache is a so-called HTTP cache accelerator – in short: it saves your website as a static copy in your server’s memory and delivers this copy directly on request at lightning speed. This means that dynamic content does not have to be regenerated by the backend or the database for every request. This reduces the load on the server and speeds up delivery enormously.
How Varnish works at a glance:
- First call of a page:
- A user calls up a page of your store. This request is routed to the database and Shopware’s PHP system to generate the content.
- Varnish saves the generated result (HTML) in its cache.
- The following calls:
- The next user receives the page directly from the Varnish cache – without a detour via the backend.
- Delivery takes place in just a few milliseconds, while the load on the server is drastically reduced.
Why is Varnish particularly suitable for Shopware?
- Optimum performance with high traffic: Varnish is particularly helpful for highly frequented stores, as it processes requests very efficiently.
- Customizability: You can use your own rules (VCL – Varnish Configuration Language) to tailor the cache to your requirements, e.g. do not cache user-specific pages or exclude certain cookies.
- Integration with modern store systems: Shopware 6.6 already supports Varnish and allows easy integration into the existing caching system.
Setting up Varnish on a Shopware 6.6 Linux server
Setting up Varnish Cache may seem complicated at first, but it can be easily implemented step by step. Here is a guide specifically for Shopware 6.6 on a Linux server:
1. requirements
Before you install Varnish, make sure:
- You have a Linux-based server (Ubuntu 20.04 or higher, CentOS).
- A configured Shopware 6.6 store is active on your web server.
- Your web server is either Apache or NGINX.
Preparing the installation of the store
Since Varnish acts as a proxy between your web server and the client, support your store by activating cache tags (important for dynamic caching). Shopware caching works well with Varnish as an additional layer.
2. install Varnish
For Ubuntu:
sudo apt update sudo apt install varnish
For CentOS:
sudo yum install varnish
Check the installation:
Check whether Varnish has been installed correctly:
varnishd -V
3. change the default port
By default, Varnish listens on port 6081, while your web server (e.g. NGINX or Apache) runs on port 80. You need to change this so that Varnish accepts requests via port 80.
Edit the Varnish configuration file:
sudo nano /etc/varnish/default.vcl
Customize the following configuration:
backend default { .host = "127.0.0.1"; .port = "8080"; // Dein Webserver (Apache/NGINX-Port) }
Requests to Varnish are now forwarded via port 80.
Then restart Varnish:
sudo systemctl restart varnish
4. prepare Shopware 6.6 for Varnish
- Activate cache: Navigate to
Einstellungen > Cache
in the Shopware backend. Make sure that the cache is activated. - Use Varnish in proxy mode: Shopware can be configured to pass cache headers to Varnish.
To do this, edit the .env
file in your Shopware installation:
SHOPWARE_HTTP_CACHE_ENABLED=1 SHOPWARE_HTTP_DEFAULT_TTL=7200
Then clear the cache:
php bin/console cache:clear
Test results and comparison: before vs. after
Before (without varnish):
- Loading time of the start page: approx. 1.5-2.0 seconds
- Processing time per request: 100-300ms
- Requests processed in parallel (with 100 users): high server load (CPU up to 80 %)
After (activated with Varnish):
- Loading time of the start page: < 500ms
(for cached pages!) - Processing time per request: 2-6ms
(cache is delivered directly without backend) - Requests processed in parallel (with 100 users): drastically lower server load (CPU up to max. 30 %)
Varnish often processes several hundred requests within seconds, while the database is almost completely unburdened. This is a great advantage, especially for heavily frequented stores.
Common pitfalls and solutions
- Cookies in the cache:
- Problem: User-specific cookies (e.g. shopping cart content, session data) could lead to incorrect cache content.
- Solution: Configure Varnish to ignore cookies unless they are really necessary.
Example (indefault.vcl
):
if (req.http.Cookie) { return (pass); }
- Caching of dynamic content (e.g. shopping cart):
- Problem: Dynamic pages such as the shopping cart should never be cached.
- Solution: Mark these pages in the Shopware backend with no-cache tags or configure Varnish to bypass the cache for these pages.
- HTTPS problems:
- Problem: Varnish does not natively support HTTPS.
- Solution: Use a reverse proxy such as Nginx or Apache before Varnish to enable HTTPS support.
- Incorrect cache invalidation:
- Problem: Changes to the store (e.g. prices, products) are not applied immediately.
- Solution: Make sure that cache tags are activated in Shopware and that Varnish reacts correctly to the tags.
The configuration of Varnish Cache for Shopware 6.6 offers immense advantages in terms of performance and server relief. With lightning-fast loading times and efficient resource management, you can optimally prepare your store for high traffic.
Even if the setup requires a few technical steps, the use of Varnish is worthwhile, especially for high-traffic stores.
Try it out and experience the difference!