Clearing the Shopware Cache

Introduction


This article applies to both servers with "Managed" support and unmanaged servers.

Shopware stores data generated during operation in a cache directory, which is not automatically cleared and can quickly take up a lot of storage space.

In this Help Center article, we explain how to manually clear the cache and how to set up automated clearing.

Prerequisites

  • Plesk server or app server (cluster setup)
  • Shopware installation



Manually clearing the cache using the Shopware CLI


Since this command actively modifies the file system structure, it should not be executed as the root user. This will make the root user the owner and group owner of the cache directory, causing your store to immediately return a 500 error and resulting in downtime.


Establish an SSH connection with the appropriate system user on your server and navigate to the project directory of your Shopware installation:


Plesk Server

cd /var/www/vhosts/<your-domain.de>/httpdocs

App Server

cd /var/www/path/to/shopware


You can then clear the Shopware cache using the following command:

bin/console cache:clear


Depending on the size of the cache, this process can take anywhere from a few seconds to several minutes.



Automation

For live stores, we recommend automatically clearing the cache on a regular basis, ideally every 24 hours. The following options are available for automation:

Cron job via the creoline Customer Center

Create a new cron job as a guest agent command.



Recommended command for Plesk servers

/var/www/vhosts/<your-domain.de>/.phpenv/shims/php /var/www/vhosts/<your-domain.de>/httpdocs/bin/console cache:clear


The absolute path /var/www/vhosts/<your-domain.de>/.phpenv/shims/php ensures that the PHP version configured for the subscription in the Plesk Control Panel is always used correctly and that the cron job will not need to be adjusted later if this version is changed in the future.


Recommended command for app servers (cluster setup)

/usr/bin/php /var/www/path/to/shopware/bin/console cache:clear



Crontab

Alternatively, cron jobs can be created directly on the server using the server’s crontab.


However, we recommend using the cron job feature via the creoline Customer Center.


Log in to your server via SSH as the system user for your website and execute the following command:

crontab -e


The first time you edit the crontab with this user, you will be prompted to select an editor. We recommend nano; the default selection (usually 1) can be confirmed simply by pressing Enter.


The syntax for crontab is as follows:

┌───────────── Minute (0 - 59)
│ ┌───────────── Hour (0 - 23)
│ │ ┌───────────── Day of the month (1–31)
│ │ │ ┌───────────── Month (1–12)
│ │ │ │ ┌───────────── Day of the week (0 - 6)
│ │ │ │ │
* * * * *  <Command/script (absolute path)>


For example, the following cron job runs every day at 12:01 a.m.:

0 1 * * * /usr/bin/php /var/www/vhosts/<Shopware-Domain>/httpdocs/bin/console cache:clear

Then save the cron job (if using nano, press Ctrl + s) and exit the editor (if using nano, press Ctrl + x).



Common Error Messages

Error 500 After Clearing the Cache

Error 500 may occur after clearing the cache if the command was executed either as the root user or as an alternative system user with higher privileges.

Verification on a Plesk Server

ls -l /var/www/vhosts/<your-domain.de>/httpdocs/var/cache


The output looks like this if the bin/console cache:clear command was executed as the root user:

total 16
-rw-r--r-- 1 root root   43 Dec 22 12:58 CACHEDIR.TAG
-rw-r--r-- 1 creoline_demo psacln  118 Dec 22 10:27 opcache-preload.php
drwxr-xr-x 8 creoline_demo psacln 4096 Dec 22 10:27 prod_h6e0ca75dfec54735ecd3e920f4256bc8
drwxr-xr-x 8 root root 4096 Dec 22 14:38 prod_h88fb4bafd76cee9f69dabda96a678a12


Solution for Plesk Servers


The placeholder <system-user> must be replaced with the system user of the associated Plesk subscription or the corresponding system user (app server):

chown -R <system-user>:psacln /var/www/vhosts/<your-domain.de>/httpdocs/var/cache


Verification on the Plesk server after the fix

ls -l /var/www/vhosts/<your-domain.de>/httpdocs/var/cache
total 16
-rw-r--r-- 1 creoline_demo creoline_demo   43 Dec 22 12:58 CACHEDIR.TAG
-rw-r--r-- 1 creoline_demo creoline_demo  118 Dec 22 10:27 opcache-preload.php
drwxr-xr-x 8 creoline_demo creoline_demo 4096 Dec 22 10:27 prod_h6e0ca75dfec54735ecd3e920f4256bc8
drwxr-xr-x 8 creoline_demo creoline_demo 4096 Dec 22 14:38 prod_h88fb4bafd76cee9f69dabda96a678a12


Verification on the App Server (Cluster Setup)

ls -l /var/www/path/to/shopware/var/cache


The output looks like this, provided the bin/console cache:clear command was executed as the root user:

total 16
-rw-r--r-- 1 root root   43 Dec 22 12:58 CACHEDIR.TAG
-rw-r--r-- 1 deployer deployer  118 Dec 22 10:27 opcache-preload.php
drwxr-xr-x 8 deployer deployer 4096 Dec 22 10:27 prod_h6e0ca75dfec54735ecd3e920f4256bc8
drwxr-xr-x 8 root root 4096 Dec 22 14:38 prod_h88fb4bafd76cee9f69dabda96a678a12


Solution for App Server (Cluster Setup)

chown -R deployer:deployer /var/www/path/to/shopware/var/cache


Verification on the App Server after the fix

ls -l /var/www/path/to/shopware/var/cache
total 16
-rw-r--r-- 1 deployer deployer   43 Dec 22 12:58 CACHEDIR.TAG
-rw-r--r-- 1 deployer deployer  118 Dec 22 10:27 opcache-preload.php
drwxr-xr-x 8 deployer deployer 4096 Dec 22 10:27 prod_h6e0ca75dfec54735ecd3e920f4256bc8
drwxr-xr-x 8 deployer deployer 4096 Dec 22 14:38 prod_h88fb4bafd76cee9f69dabda96a678a12