In this article you will find tips and technical information about the correct setting and configuration of the caches of your Shopware system. These are to be regarded as suggestions and are largely based on support cases that have already occurred and feedback from our customers. This post serves as a supplement to our caching blog series and the official Shopware documentation.
Solltest du Fragen haben, die du nicht mit diesem Leitfaden beantworten kannst, wende dich an den Support.
Table of contents
Check the status of the APCu cache
III. Deactivate web server caches
IV. Varnish reverse proxy cache for large shops
V. Manually delete Shopware cache folder
I. PHP-OPcache
Most components of Shopware and our Pickware modules are written in the script language PHP. When a page is opened, the corresponding scripts on your web server are first converted into precompiled code by the PHP module and then executed. In order to shorten the loading time of your shop pages for your customers, PHP can store already compiled scripts in the PHP OPcache. This eliminates the need for time-consuming and computationally intensive compilation when the page is called up again.
In order to optimally adapt the PHP OPcache to your requirements, PHP offers you a variety of setting options. We show you which settings you should pay particular attention to and how you can optimise the OPcache for large shops.
Requirements
- First check in your Shopware backend whether the PHP OPcache is already activated. To do this, open the Performance window under Configuration → Caches/performance → Caches/performance and switch to Settings → Performance checks. If the cache is activated, a green tick should appear next to Zend OPcache, otherwise a red X.
- In addition, check the PHP version installed on your web server. All settings shown below require at least PHP 5.5. However, we strongly recommend the use of PHP 7.0 or higher in order to benefit from maximum performance and security. You can tell if you have the latest version installed by the green tick for the PHP version in the Performance checks window. If you are using an older version, a warning triangle is displayed instead.
Important OPcache settings
All PHP settings are usually stored in the php.ini file on your web server. The directory in which this file is located depends on your server configuration. You can find out the exact location in the backend under Configuration → System Info → PHP Info → Loaded Configuration File.
If you edit the php.ini file, you should first make a backup. Then save the document and restart your web server so that the changes are applied.
Your php.ini file contains many settings to configure PHP. The following settings are recommended so that your OPcache works optimally and error-free with Shopware:
- opcache.enable: On (Default: On)
Activate the PHP opcache on your web server. If this was previously deactivated, you should activate it now.
- opcache.validate_timestamps: On (Default: On)
This setting must be activated so that PHP regularly checks the stored scripts for changes and updates them if necessary. This usually eliminates the need to manually empty the cache.
- opcache.revalidate_freq: 2 (Default: 2)
Indicates how often (in seconds) the cached scripts are checked for changes.
- opcache.use_cwd: On (Default: On)
When activated, PHP links the workspace 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 must be set to On! This avoids overlapping of the cache system with that of other websites on the same physical server when activated.
- opcache.save_comments: On (Default: On)
This setting takes into account the loading of comments in the source code. This should definitely be activated, as some Shopware modules require this function.
Scale OPcache for large shops
For most Shopware shops, the default settings of the PHP OPcache should already provide sufficient performance. However, if you run 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 maximum usable memory in megabytes to the OPcache. 128MB is sufficient for most smaller shops. For very large shops or with many additional installed modules, you can increase the value to 256 or more. You can see the current memory usage of the cache in the backend under Configuration → System info → PHP info → Zend OPcache → Used memory and Free memory.
- opcache.max_accelerated_files: 10000/12500/15000 (Default: 10000)
The 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 RAM available, the value can be increased accordingly to improve performance. The ratio of the numbers cache misses to cache hits in the backend under Settings → System info → PHP info → Zend OPcache provides a clue. If the ratio is greater than 1%, increasing the setting could improve performance. However, additionally consider whether the cache memory is sufficiently large, see opcache.memory_consumption.
You can find an overview of all OPcache settings in the official PHP documentation. Shopware also offers some information on the use of the OPcache.
II. PHP APCu-Cache
The PHP APCu cache enables PHP-based programmes such as Shopware to shop frequently used data, e.g. shop settings, user data, frequently executed database queries, etc., in the web server's main memory. Shopware supports the use of the APCu cache and can further reduce the loading times of your shop by using it.
Check the status of the APCu cache
First, you should check whether the APCu cache is already activated on your web server. To do this, go to Configuration → Caches/Performance → Settings → Performance checks in your backend. If APCu is enabled, there should be a green tick, if there is a red X, APCu is disabled on your server.
Activate APCu-Cache
To activate the APCu cache, the corresponding PHP module must first be installed on your web server. This must then be activated via an entry in php.ini. To do this, contact the hoster of your web server or use the official PHP documentation.
III. Deactivate web server caches
Many web servers offer their own caching modules which, analogous to Shopware's own HTTP cache, store frequently accessed websites in your shop in order to speed up access. In the vast majority of cases, however, these caches should remain deactivated, as they will otherwise lead to conflicts with the Shopware HTTP cache. Shopware can only perform a cache invalidation, i.e. the updating or deletion of changed elements in the cache, with its own cache, whereby the caches of the web server would continue to deliver old versions of your website. An exception is the connection of reverse proxy caches to 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. Therefore, please check that these three Apache modules are disabled. This is only possible via the command line tool of your web server, the necessary commands depend on your server operating system and require the appropriate permissions. If necessary, contact your hoster.
nginx
The nginx web server is not officially supported by Shopware, but is nevertheless very popular among Shopware users due to its good performance. nginx offers its own cache, the nginx fastcgi_cache, in the fastCGI module. Analogous to the Apache caches, this should remain deactivated to avoid conflicts with Shopware. It is best to check this on your web server.
IV. Varnish reverse proxy cache for large shops
If Shopware's own HTTP cache is not sufficient for your shop, the use of upstream caches, so-called reverse proxy caches, could offer a solution. These caches are part of a reverse proxy server, which is connected in front of your actual web server and first receives all web requests to your shop. Then, with the help of the integrated cache, it will try to answer the requests on its own, i.e. generate the requested websites or their elements from its own cache. If the request cannot be answered with the reverse proxy cache, it is forwarded to the normal web server and thus to the Shopware system, which processes the request as usual.
Performance & requirement
Due to higher performance and configurability, reverse proxy caches can increase the maximum number of simultaneous customers in your shop and usually improve the loading speed of your shop. However, these reverse proxy caches must be supported by and perfectly matched to the Shopware system, because permanent communication between Shopware and the cache is necessary for error-free cache validation.
Varnish-Cache
The Varnish cache is a powerful reverse proxy cache and replaces Shopware's own HTTP cache. However, in order to integrate the Varnish cache into Shopware and for the cache invalidation to work, a Shopware 5 Enterprise licence is required. All information on setting up the Varnish cache under Shopware can be found here.
V. Manually delete 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 empty the contents of the caches in question. To do this, you need access to the file system of your web server. Then change to the document directory of your web server, 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 cache folders concerned and then delete them.