Recurring problems in Mautic system / system then not accessible

Hello,

We have recurring problems in our Mautic test system. Whenever these occur I have to call a fix script from my developer to correct cache and directory permissions.

We don’t know what causes these problems.

There are errors in the logs like:

[2024-01-13 04:43:29] mautic.WARNING: PHP Warning - Undefined variable $inline - in file /var/www/mautic-testsystem.de/offline.php - at line 77 [] {"hostname":"mautic-staging","pid":355937}
[2024-01-13 04:43:29] mautic.ERROR: Symfony\Component\Filesystem\Exception\IOException: Cannot rename "/tmp/catalogue.en_US.l8NCL8I.phpUf139v" to "/var/www/mautic-testsystem.de/var/cache/prod/translations/catalogue.en_US.l8NCL8I.php". - in file /var/www/mautic-testsystem.de/vendor/symfony/filesystem/Filesystem.php - at line 290 [] {"hostname":"mautic-staging","pid":355937}
[2024-01-13 04:43:42] mautic.CRITICAL: Uncaught PHP Exception Symfony\Component\Filesystem\Exception\IOException: "Cannot rename "/tmp/catalogue.en_GB.l8NCL8I.phpDpEV5X" to "/var/www/mautic-testsystem.de/var/cache/prod/translations/catalogue.en_GB.l8NCL8I.php"." at /var/www/mautic-testsystem.de/vendor/symfony/filesystem/Filesystem.php line 290 {"exception":"[object] (Symfony\\Component\\Filesystem\\Exception\\IOException(code: 0): Cannot rename \"/tmp/catalogue.en_GB.l8NCL8I.phpDpEV5X\" to \"/var/www/mautic-testsystem.de/var/cache/prod/translations/catalogue.en_GB.l8NCL8I.php\". at /var/www/mautic-testsystem.de/vendor/symfony/filesystem/Filesystem.php:290)"} {"hostname":"mautic-staging","pid":342758}
[2024-01-13 04:44:30] mautic.WARNING: PHP Warning - require(/var/www/mautic-testsystem.de/var/cache/prod/doctrine/orm/Proxies/__CG__MauticPluginBundleEntityPlugin.php): Failed to open stream: No such file or directory - in file /var/www/mautic-testsystem.de/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php - at line 197 [] {"hostname":"mautic-staging","pid":342758}
[2024-01-13 04:44:30] mautic.CRITICAL: Uncaught PHP Exception Symfony\Component\Debug\Exception\FatalThrowableError: "Failed opening required '/var/www/mautic-testsystem.de/var/cache/prod/doctrine/orm/Proxies/__CG__MauticPluginBundleEntityPlugin.php' (include_path='.:/usr/share/php')" at /var/www/mautic-testsystem.de/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php line 197 {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Failed opening required '/var/www/mautic-testsystem.de/var/cache/prod/doctrine/orm/Proxies/__CG__MauticPluginBundleEntityPlugin.php' (include_path='.:/usr/share/php') at /var/www/mautic-testsystem.de/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php:197)"} {"hostname":"mautic-staging","pid":342758}
[2024-01-13 05:00:09] mautic.WARNING: PHP Warning - require(/var/www/mautic-testsystem.de/var/cache/prod/doctrine/orm/Proxies/__CG__MauticPluginBundleEntityPlugin.php): Failed to open stream: No such file or directory - in file /var/www/mautic-testsystem.de/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php - at line 197 [] {"hostname":"mautic-staging","pid":355937}
[2024-01-13 05:00:09] mautic.CRITICAL: Uncaught PHP Exception Symfony\Component\Debug\Exception\FatalThrowableError: "Failed opening required '/var/www/mautic-testsystem.de/var/cache/prod/doctrine/orm/Proxies/__CG__MauticPluginBundleEntityPlugin.php' (include_path='.:/usr/share/php')" at /var/www/mautic-testsystem.de/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php line 197 {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Failed opening required '/var/www/mautic-testsystem.de/var/cache/prod/doctrine/orm/Proxies/__CG__MauticPluginBundleEntityPlugin.php' (include_path='.:/usr/share/php') at /var/www/mautic-testsystem.de/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php:197)"} {"hostname":"mautic-staging","pid":355937}

The server runs Mautic version v4.4.10 with PHP version 8.0.28 and MySQL 8.0.18-google.

Do you have an idea why this could be and how this problem can be solved sustainably?

Best regards

Timo

Could it be that you ran e.g. a “cache:clear” with the wrong user (probably root)?
The entire Mautic folder structure and specifically var/cache (in your case: /var/www/mautic-testsystem.de/var/cache) must belong to the webserver’s user account (e.g. www-data).

I would advice against owning all the files inside mautic as www-data as its a security risk. Only folders/files that are used by mautic app should be writable. Thos folders are (mautic 4):

  • var
  • media
  • themes
  • app/config/local.php

I might have forgotten some folder (if I did, please add it on the reply), but that should be most of it.

Thanks for your feedback.

I checked the cache directory and found that many data/directories were not running on www-data but on root.

We then defined the execution of the crons in the www-data crontab. So far it looks like the problem no longer occurs.

Thank you for the tips and help on this!

I would advice against owning all the files inside mautic as www-data as its a security risk. Only folders/files that are used by mautic app should be writable.

And does this also apply to the cache directory?

Yes, the cache directory too. Its usually under var/cache folder.