In this article, you'll find tips and technical information on the correct configuration of the caches in your Shopware system. These should be considered as suggestions and are largely based on support cases that have already occurred and feedback from our customers. This article serves as a supplement to our caching blog series as well as the official Shopware documentation.
If you have questions that this guide doesn't answer, contact support.
Safety note: All steps shown in this article are performed at your own risk. Changing or deleting files on your server can, in the worst case, cause your system to fail. Changes should therefore first be made on a test shop. Create backups of your current configuration before making any changes. If in doubt, please contact your shop's hosting provider before changing the settings shown here.
Table of contents
I. PHP OPcache
Most components of Shopware and our Pickware modules are written in the PHP scripting language. When a page is loaded, the corresponding scripts on your web server are first converted into precompiled code by the PHP module and then executed. To reduce the loading time of your shop pages for your customers, PHP can store already compiled scripts in the PHP OPcache. This eliminates the time- and resource-intensive compilation on repeated calls.
To optimally adapt the PHP OPcache to your requirements, PHP offers a wide range of configuration options. We'll show you which settings you should pay particular attention to and how to optimize the OPcache for large shops.
Requirements
First, check in your Shopware backend whether the PHP OPcache is already enabled. To do this, open the Performance window under Settings → Caches/Performance → Caches/Performance and switch to the Settings → Performance checks tab. If the cache is enabled, a green checkmark should appear for Zend OPcache; otherwise a red X.
Also check the PHP version installed on your web server. All the settings shown below require at least PHP 5.5. However, we explicitly recommend using PHP 7.0 or higher to benefit from maximum performance and security. You can tell whether you have the latest version installed by the green checkmark for PHP version in the Performance checks window. If you're using an older version, a warning triangle will be displayed instead.
Tip: You can view the exact version number of your PHP installation as well as all set PHP settings at any time in your backend under Settings → System info → PHP info.
Important OPcache settings
All PHP settings are usually stored in the php.ini file on your web server. The directory it's located in depends on your server configuration. You can find the exact location in the backend under Settings → System info → PHP info → Loaded Configuration File:
If you edit the php.ini, you should first create a backup of this file. Then save the document and restart your web server so that the changes take effect.
Your php.ini file contains many settings for configuring PHP. The following settings are recommended so that your OPcache works optimally and without errors with Shopware:
opcache.enable: On (Default: On)
Enable the PHP OPcache on your web server. If it has been disabled so far, you should enable it now.
opcache.validate_timestamps: On (Default: On)
This setting must be enabled so that PHP regularly checks the stored scripts for changes and updates them if necessary. This usually means you don't need to clear the cache manually.
opcache.revalidate_freq: 2 (Default: 2)
Specifies how often (in seconds) the cached scripts are checked for changes.
opcache.use_cwd: On (Default: On)
When enabled, PHP links the working directory in the cache to the respective script. This avoids collisions between files with the same file name.
opcache.validate_root: On/Off (Default: Off)
If your web server is installed on a shared hosting system, this option absolutely must be set to On! When enabled, this prevents overlaps between the cache system and that of other websites on the same physical server.
opcache.save_comments: On (Default: On)
This setting takes into account the loading of comments in the source code. This should definitely be enabled, as some Shopware modules require this function.
Note: Instead of On/Off, your php.ini file can alternatively use true/false. Both forms can be used equivalently.
Scaling OPcache for large shops
For most Shopware shops, the default settings of the PHP OPcache should already offer sufficient performance. However, if you're running very large shops and/or many installed plugins on your web server, you can adjust the following settings to increase performance:
opcache.memory_consumption: 128/256/512 (Default: 128)
This option assigns the OPcache the maximum usable memory in megabytes. 128MB is sufficient for most smaller shops. For very large shops or if you have many additional modules installed, you can increase the value to 256 or more. You can view the current memory usage of the cache in the backend under Settings → System info → PHP info → Zend OPcache → Used memory and Free memory.
opcache.max_accelerated_files: 10000/12500/15000 (Default: 10000)
This setting specifies the maximum number of PHP scripts that can be stored in the OPcache. A typical Shopware 5 installation uses about 7000 scripts. If you use many additional modules and have enough free memory available, you can increase the value accordingly to improve performance. A useful reference point is the ratio of Cache misses to Cache hits in the backend under Settings → System info → PHP info → Zend OPcache. If the ratio is higher than 1%, increasing this setting could improve performance. However, also consider whether the cache's storage space is sufficiently sized, see opcache.memory_consumption.
You can find an overview of all OPcache settings in the official PHP documentation. Shopware also offers some information on using the OPcache.
II. PHP APCu cache
The PHP APCu cache allows PHP-based programs like Shopware to store frequently needed data, e.g. shop settings, user data, frequently performed database queries, etc., in the working memory of the web server. Shopware supports the use of the APCu cache and can further reduce your shop's loading times by using it.
Checking the status of the APCu cache
First, check whether the APCu cache is already enabled on your web server. To do this, go to Settings → Caches/Performance → Caches/Performance → Settings → Performance checks in your backend. A green checkmark should be set for APCu enabled; a red X means APCu is disabled on your server.
Enabling the APCu cache
To enable the APCu cache, the corresponding PHP module must first be installed on your web server. It must then be enabled via an entry in the php.ini. Contact your web server's hosting provider for this, or use the following guide as well as the official PHP documentation.
Note: The APCu cache is used by PHP across all websites hosted on a web server. For security reasons, this should never be enabled on shared hosting servers! You'll therefore need a "dedicated web server" from a hosting provider where the memory isn't shared with other customers' applications.
III. Disabling web server caches
Many web servers offer their own caching modules, which, similar to Shopware's own HTTP cache, store frequently accessed pages of your shop to speed up repeated access. In most cases, however, these caches should absolutely remain disabled, as they otherwise lead to conflicts with the Shopware HTTP cache. Shopware can only perform cache invalidation, i.e. updating or deleting changed elements in the cache, with its own cache, which means the web server's caches would continue to serve old versions of your website. An exception is the integration of reverse proxy caches with Shopware. The affected caches of the respective web servers are explained below.
Apache
Apache is the web server officially recommended by Shopware and offers two optional caching methods: mod_disk_cache and mod_mem_cache, with the parent module mod_cache. Please check that these three Apache modules are disabled. This is only possible via your web server's command line tool; the necessary commands depend on the server operating system you're using and require appropriate permissions. If necessary, contact your hosting provider for this.
Note: Don't confuse the Apache module mod_mem_cache with the Memcached system and the associated PHP Memcache module, which can optionally be used in some Shopware configurations for session handling.
nginx
Although the nginx web server isn't officially supported by Shopware, it's still very popular among Shopware users due to its good performance. nginx offers its own cache in the fastCGI module, the nginx fastcgi_cache. Just like the Apache caches, this should absolutely remain disabled to avoid conflicts with Shopware. It's best to check this on your web server.
IV. Varnish reverse proxy cache for large shops
If Shopware's own HTTP cache isn't sufficient for your shop, using upstream caches, so-called reverse proxy caches, could offer a solution. These caches are part of a reverse proxy server, which is placed in front of your actual web server and initially receives all web requests to your shop. It then attempts to answer the requests independently using the integrated cache, i.e. generating the requested pages or their elements from its own cache. If the request can't be answered with the reverse proxy cache, it's forwarded to the normal web server and thus the Shopware system, which processes the request as usual.
Performance & requirements
Due to higher performance and configurability, reverse proxy caches can increase the maximum number of simultaneous customers in your shop and usually improve your shop's loading speed. However, these reverse proxy caches must be supported by the Shopware system and perfectly matched to it, as permanent communication between Shopware and the cache is necessary for error-free cache invalidation.
Varnish cache
The Varnish cache is a powerful reverse proxy cache and thus replaces Shopware's own HTTP cache. However, a Shopware 5 Enterprise license is required so that the Varnish cache can be integrated into Shopware and cache invalidation works. You can find all information on setting up the Varnish cache with Shopware here.
Note: Extending Shopware with a reverse proxy creates an additional layer of complexity and should only be considered if absolutely necessary. This requires extensive knowledge of your server structure and requirements, and many hosting providers can only offer limited support here.
V. Manually deleting the Shopware cache folder
In exceptional cases, it can happen that Shopware caches block the start of your entire Shopware backend. In such cases, you can manually clear the contents of the affected caches. To do this, you need access to your web server's file system. Then switch to your web server's document directory, e.g. /var/www/. The individual caches are located in the following subdirectories:
Shopware configuration: var/cache/production_XXX/general/
Shopware HTTP cache: var/cache/production_XXX/html/
Templates: var/cache/production_XXX/templates/
Themes: web/cache/
Shopware proxies: var/cache/production_XXX/proxies/
Doctrine proxies: var/cache/production_XXX/doctrine/proxies/
To delete, select the entire contents of the affected cache folders and then delete them.
Attention: Be sure to create a backup of these folders before deleting them, so you can restore them if needed!
