Empty Shopware cache

Preface


The article is suitable for servers in the "Managed" support level as well as for unmanaged servers.

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

In this Help Center article, we explain manual cache cleanup and how to set up automated cleanup.

Prerequisites

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



Empty cache manually via Shopware CLI


As the command actively intervenes in the file system structure, it should not be executed with the root user. The root user will become the owner and group owner of the cache directory, which will cause your store to directly return an error 500 and result in downtime.


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


Plesk server

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

**app server

cd /var/www/path/to/shopware


The Shopware cache can then be emptied with the following command:

bin/console cache:clear


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



Automation

For productive stores, we recommend that the cache is cleaned automatically on a regular basis, ideally every 24 hours. The following automation options are available:

Cronjob via the creoline customer center

Create a new cronjob as a guest agent command.



Recommended command for Plesk server

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


The absolute path /var/www/vhosts/<your-domain.com>/.phpenv/shims/php ensures that the PHP version of the subscription set in the Plesk Control Panel is always used correctly and that the cronjob does not have to be adjusted in future if this is changed.


Recommended command for app server (cluster setup)

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



Crontab

Alternatively, cronjobs can be created on the server itself via the server's crontab.


Nevertheless, we recommend using the cronjob function via the creoline Customer Center.


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

crontab -e


When editing the crontab with this user for the first time, you will be asked for the editor to be used. We recommend nano; the preselection (usually 1) can simply be confirmed with Enter.


The syntax for the 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)>


As an example, the following cron job is executed every day at 00:01:

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

Then save the cronjob (if nano, Ctrl + s) and exit the editor (if nano, Ctrl + x).



Frequent error messages

Error 500 after clearing the cache

Error 500 can occur after emptying the cache if the command was executed with either the root user or an alternative system user with higher authorizations.

Verification on Plesk server

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


The output looks like this if the bin/console cache:clear command was executed with 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 server


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

chown -R <systemuser>:psacln /var/www/vhosts/<your-domain.com>/httpdocs/var/cache


Verification on Plesk server after the fix

ls -l /var/www/vhosts/<your-domain.com>/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 app server (cluster setup)

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


The output looks as follows if the bin/console cache:clear command was executed with 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 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