Instance broken after clearing cache the wrong way. Reset permissions and owner does not help (yet)

Your software
My Mautic version is: 4.4.4, fresh install from zip file.
My PHP version is: 7.4.30
My Database type and version is: mysql Ver 15.1 Distrib 10.5.15-MariaDB, for debian-linux-gnu (x86_64)
Web sever: nginx 1.18.0

Your problem
My problem is: I removed the cache as sudo user (sudo rm -rf var/cache/* which I should not have done). After that the mautic page is down.

It is still not working.

These errors are showing in the log:

[2022-11-11 13:02:45] mautic.CRITICAL: Uncaught PHP Exception Symfony\Component\Filesystem\Exception\IOException: "Cannot rename "/tmp/UrlMatcher.phpIClvgH" to "/var/www/html/mautic/var/cache/prod/UrlMatcher.php"." at /var/www/html/mautic/vendor/symfony/filesystem/Filesystem.php line 290 {"exception":"[object] (Symfony\\Component\\Filesystem\\Exception\\IOException(code: 0): Cannot rename \"/tmp/UrlMatcher.phpIClvgH\" to \"/var/www/html/mautic/var/cache/prod/UrlMatcher.php\". at /var/www/html/mautic/vendor/symfony/filesystem/Filesystem.php:290)"} {"hostname":"vps","pid":32368}
[2022-11-11 13:02:45] mautic.NOTICE: PHP Notice - Undefined variable: inline - in file /var/www/html/mautic/offline.php - at line 77 {"inTemplate":true,"isAjax":false,"message":"The site is currently offline due to encountering an error. If the problem persists, please contact the system administrator.","submessage":"System administrators, check server logs for errors.","inDev":false,"base":"/","root":"/var/www/html/mautic","assetPrefix":"","paths":{"themes":"themes","assets":"media","asset_prefix":"","plugins":"plugins","translations":"translations","local_config":"%kernel.root_dir%/config/local.php","root":"/var/www/html/ma","app":"app","bundles":"app/bundles","vendor":"vendor"},"assetBase":"/media"} {"hostname":"vps","pid":32368}
[2022-11-11 13:02:45] mautic.ERROR: Symfony\Component\Filesystem\Exception\IOException: Cannot rename "/tmp/UrlGenerator.phpICXWeH" to "/var/www/html/mautic/var/cache/prod/UrlGenerator.php". - in file /var/www/html/mautic/vendor/symfony/filesystem/Filesystem.php - at line 290 [] {"hostname":"vps","pid":32368}
[2022-11-11 13:34:03] mautic.NOTICE: PHP Notice - SessionHandler::gc(): ps_files_cleanup_dir: opendir(/var/lib/php/sessions) failed: Permission denied (13) - in file /var/www/html/mautic/vendor/symfony/http-foundation/Session/Storage/Handler/StrictSessionHandler.php - at line 106 {"maxlifetime":1440} {"hostname":"vps","pid":524}
[2022-11-11 13:54:43] mautic.NOTICE: PHP Notice - SessionHandler::gc(): ps_files_cleanup_dir: opendir(/var/lib/php/sessions) failed: Permission denied (13) - in file /var/www/html/mautic/vendor/symfony/http-foundation/Session/Storage/Handler/StrictSessionHandler.php - at line 106 {"maxlifetime":1440} {"hostname":"vps","pid":523}

Steps I have tried to fix the problem:

  1. I reset the permissons and owner of the mautic directory, clear the cache following this guide https://docs.mautic.org/en/troubleshooting/file-ownership-and-permissions. This time I perform the commands as the user of the web server. Still not working.

as www-data, I ran:

find . -type f -not -perm 644 -exec chmod 644 {} +
find . -type d -not -perm 755 -exec chmod 755 {} +
chmod -R g+w var/cache/ var/logs/ app/config/
chmod -R g+w media/files/ media/images/ translations/
rm -rf var/cache/*

as sudo, I ran:

sudo chown -R www-data:www-data /path/to/mautic

  1. restart php, nginx and the server. it does not help.

  2. I think this is related to the permisson, but don’t know what to do more than the link above.

Thank you for your support. Cheers.

1 Like

now that your file ownership is fixed, please try
sudo -u www-data php /<path/to/mautic>/bin console cache:clear

Thank you @ekke for your quick reply. I did clear the cache that way, again as you suggested. The site is still broken.

In between, I see another message coming, maybe due to one of the cronjob that I set.

[2022-11-11 14:26:09] mautic.NOTICE: PHP Notice - SessionHandler::gc(): ps_files_cleanup_dir: opendir(/var/lib/php/sessions) failed: Permission denied (13) - in file /var/www/html/mautic/vendor/symfony/http-foundation/Session/Storage/Handler/StrictSessionHandler.php - at line 106 {"maxlifetime":1440} {"hostname":"vps","pid":1248}

Hmm , not sure this is related, it is only a notice (affecting the cleanup) which should not break the system. I would guess it was there before your issues started.

So… are we sure your web server is running under the www-data user?

I think nginx is running under www-data

sudo ps aux| grep nginx
root         984  0.0  0.0  59164  1772 ?        Ss   09:05   0:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
www-data     985  0.0  0.2  59400  5348 ?        S    09:05   0:00 nginx: worker process
www-data     986  0.0  0.2  59400  5348 ?        S    09:05   0:00 nginx: worker process

Ok… I keep asking the simple questions, because just deleting var/cache/* should not cause serious issues:

  • did you check the Mautic logs, too? (in /var/log)
  • can you share an ls -lR /var/cache/ ?

@ekke you are right. it’s better to start with simple things.

the output you asked for are here: nginx log error and cache

thank you for your time.

Uuuh - Cache files all owned by root!
Try another
rm -rf /var/cache/*
plus clear cache see above

I’m sorry, you asked for the /var/cache/ of the system or the /path/to/mautic/var/cache ?

P.S. when looking at logs don’t forget /var/log/

Oh, /var/cache/* of course!!!
Sorry :innocent:

here is mautic cache . the nginx error in /var/log I posted in last post. Please tell if these are the output you need. The details start to get out of my comprehension :smiley:

after this, nothing left in /var/cache/* to show you :smiley:

Try the following:

  • move to /var/cache
  • mkdir -p dev prod
  • move to
  • php bin/console mautic:plugins:reload
  • chown -R www-data:root dev
  • chown -R www-data:root prod

I tried the commands. open the page with different browsers. still not working.

what does the log say under var/logs?

There are three files. I show the last lines of two files here. The time stamp might not be correct. I changed the time zone end of this afternoon.

ls -l var/logs/
-rw-rw-r-- 1 www-data www-data 73692 Nov  5 23:45 mautic_prod-2022-11-05.php
-rw-rw-r-- 1 www-data www-data 60446 Nov 11 21:39 mautic_prod-2022-11-11.php
-rw-rw-r-- 1 www-data www-data  2940 Nov 11 16:32 prod-2022-11-11.php

vincent@vps:/var/www/html/mautic$ sudo tail -20 var/logs/mautic_prod-2022-11-11.php

[2022-11-11 13:02:45] mautic.ERROR: Symfony\Component\Filesystem\Exception\IOException: Cannot rename "/tmp/UrlGenerator.phpNLcuzM" to "/var/www/html/mautic/var/cache/prod/UrlGenerator.php". - in file /var/www/html/mautic/vendor/symfony/filesystem/Filesystem.php - at line 290 [] {"hostname":"vps","pid":32369}
[2022-11-11 13:02:45] mautic.CRITICAL: Uncaught PHP Exception Symfony\Component\Filesystem\Exception\IOException: "Cannot rename "/tmp/UrlMatcher.phpIClvgH" to "/var/www/html/mautic/var/cache/prod/UrlMatcher.php"." at /var/www/html/mautic/vendor/symfony/filesystem/Filesystem.php line 290 {"exception":"[object] (Symfony\\Component\\Filesystem\\Exception\\IOException(code: 0): Cannot rename \"/tmp/UrlMatcher.phpIClvgH\" to \"/var/www/html/mautic/var/cache/prod/UrlMatcher.php\". at /var/www/html/mautic/vendor/symfony/filesystem/Filesystem.php:290)"} {"hostname":"vps","pid":32368}
[2022-11-11 13:02:45] mautic.NOTICE: PHP Notice - Undefined variable: inline - in file /var/www/html/mautic/offline.php - at line 77 {"inTemplate":true,"isAjax":false,"message":"The site is currently offline due to encountering an error. If the problem persists, please contact the system administrator.","submessage":"System administrators, check server logs for errors.","inDev":false,"base":"/","root":"/var/www/html/mautic","assetPrefix":"","paths":{"themes":"themes","assets":"media","asset_prefix":"","plugins":"plugins","translations":"translations","local_config":"%kernel.root_dir%/config/local.php","root":"/var/www/html/ma","app":"app","bundles":"app/bundles","vendor":"vendor"},"assetBase":"/media"} {"hostname":"vps","pid":32368}
[2022-11-11 13:02:45] mautic.ERROR: Symfony\Component\Filesystem\Exception\IOException: Cannot rename "/tmp/UrlGenerator.phpICXWeH" to "/var/www/html/mautic/var/cache/prod/UrlGenerator.php". - in file /var/www/html/mautic/vendor/symfony/filesystem/Filesystem.php - at line 290 [] {"hostname":"vps","pid":32368}
[2022-11-11 13:34:03] mautic.NOTICE: PHP Notice - SessionHandler::gc(): ps_files_cleanup_dir: opendir(/var/lib/php/sessions) failed: Permission denied (13) - in file /var/www/html/mautic/vendor/symfony/http-foundation/Session/Storage/Handler/StrictSessionHandler.php - at line 106 {"maxlifetime":1440} {"hostname":"vps","pid":524}
[2022-11-11 13:54:43] mautic.NOTICE: PHP Notice - SessionHandler::gc(): ps_files_cleanup_dir: opendir(/var/lib/php/sessions) failed: Permission denied (13) - in file /var/www/html/mautic/vendor/symfony/http-foundation/Session/Storage/Handler/StrictSessionHandler.php - at line 106 {"maxlifetime":1440} {"hostname":"vps","pid":523}
[2022-11-11 14:26:09] mautic.NOTICE: PHP Notice - SessionHandler::gc(): ps_files_cleanup_dir: opendir(/var/lib/php/sessions) failed: Permission denied (13) - in file /var/www/html/mautic/vendor/symfony/http-foundation/Session/Storage/Handler/StrictSessionHandler.php - at line 106 {"maxlifetime":1440} {"hostname":"vps","pid":1248}
[2022-11-11 15:30:18] mautic.NOTICE: Symfony\Component\Filesystem\Exception\IOException: Failed to remove file "/var/www/html/mautic/var/cache/pro~/translations/catalogue.en_US.qAY_2tt.php.meta": unlink(/var/www/html/mautic/var/cache/pro~/translations/catalogue.en_US.qAY_2tt.php.meta): Permission denied (uncaught exception) at /var/www/html/mautic/vendor/symfony/filesystem/Filesystem.php line 184 while running console command `cache:clear` [] {"hostname":"vps","pid":1674}
[2022-11-11 15:30:18] mautic.WARNING: Command `cache:clear` exited with status code 1 [] {"hostname":"vps","pid":1674}
[2022-11-11 15:30:43] mautic.NOTICE: Symfony\Component\Filesystem\Exception\IOException: Failed to remove file "/var/www/html/mautic/var/cache/pro~/translations/catalogue.en_US.qAY_2tt.php.meta": unlink(/var/www/html/mautic/var/cache/pro~/translations/catalogue.en_US.qAY_2tt.php.meta): Permission denied (uncaught exception) at /var/www/html/mautic/vendor/symfony/filesystem/Filesystem.php line 184 while running console command `cache:clear` [] {"hostname":"vps","pid":1680}
[2022-11-11 15:30:43] mautic.WARNING: Command `cache:clear` exited with status code 1 [] {"hostname":"vps","pid":1680}
[2022-11-11 15:32:34] mautic.NOTICE: Symfony\Component\Filesystem\Exception\IOException: Failed to remove file "/var/www/html/mautic/var/cache/pro~/translations/catalogue.en_US.qAY_2tt.php.meta": unlink(/var/www/html/mautic/var/cache/pro~/translations/catalogue.en_US.qAY_2tt.php.meta): Permission denied (uncaught exception) at /var/www/html/mautic/vendor/symfony/filesystem/Filesystem.php line 184 while running console command `cache:clear` [] {"hostname":"vps","pid":1685}
[2022-11-11 15:32:34] mautic.WARNING: Command `cache:clear` exited with status code 1 [] {"hostname":"vps","pid":1685}
[2022-11-11 20:39:16] mautic.NOTICE: PHP Notice - SessionHandler::gc(): ps_files_cleanup_dir: opendir(/var/lib/php/sessions) failed: Permission denied (13) - in file /var/www/html/mautic/vendor/symfony/http-foundation/Session/Storage/Handler/StrictSessionHandler.php - at line 106 {"maxlifetime":1440} {"hostname":"vps","pid":1249}
         
vincent@vps:/var/www/html/mautic$ sudo tail -20 var/logs/prod-2022-11-11.php 
[2022-11-11 15:30:18] console.CRITICAL: Error thrown while running command "cache:clear". Message: "Failed to remove file "/var/www/html/mautic/var/cache/pro~/translations/catalogue.en_US.qAY_2tt.php.meta": unlink(/var/www/html/mautic/var/cache/pro~/translations/catalogue.en_US.qAY_2tt.php.meta): Permission denied" {"exception":"[object] (Symfony\\Component\\Filesystem\\Exception\\IOException(code: 0): Failed to remove file \"/var/www/html/mautic/var/cache/pro~/translations/catalogue.en_US.qAY_2tt.php.meta\": unlink(/var/www/html/mautic/var/cache/pro~/translations/catalogue.en_US.qAY_2tt.php.meta): Permission denied at /var/www/html/mautic/vendor/symfony/filesystem/Filesystem.php:184)","command":"cache:clear","message":"Failed to remove file \"/var/www/html/mautic/var/cache/pro~/translations/catalogue.en_US.qAY_2tt.php.meta\": unlink(/var/www/html/mautic/var/cache/pro~/translations/catalogue.en_US.qAY_2tt.php.meta): Permission denied"} {"hostname":"vps","pid":1674}
[2022-11-11 15:30:43] console.CRITICAL: Error thrown while running command "cache:clear". Message: "Failed to remove file "/var/www/html/mautic/var/cache/pro~/translations/catalogue.en_US.qAY_2tt.php.meta": unlink(/var/www/html/mautic/var/cache/pro~/translations/catalogue.en_US.qAY_2tt.php.meta): Permission denied" {"exception":"[object] (Symfony\\Component\\Filesystem\\Exception\\IOException(code: 0): Failed to remove file \"/var/www/html/mautic/var/cache/pro~/translations/catalogue.en_US.qAY_2tt.php.meta\": unlink(/var/www/html/mautic/var/cache/pro~/translations/catalogue.en_US.qAY_2tt.php.meta): Permission denied at /var/www/html/mautic/vendor/symfony/filesystem/Filesystem.php:184)","command":"cache:clear","message":"Failed to remove file \"/var/www/html/mautic/var/cache/pro~/translations/catalogue.en_US.qAY_2tt.php.meta\": unlink(/var/www/html/mautic/var/cache/pro~/translations/catalogue.en_US.qAY_2tt.php.meta): Permission denied"} {"hostname":"vps","pid":1680}
[2022-11-11 15:32:34] console.CRITICAL: Error thrown while running command "cache:clear". Message: "Failed to remove file "/var/www/html/mautic/var/cache/pro~/translations/catalogue.en_US.qAY_2tt.php.meta": unlink(/var/www/html/mautic/var/cache/pro~/translations/catalogue.en_US.qAY_2tt.php.meta): Permission denied" {"exception":"[object] (Symfony\\Component\\Filesystem\\Exception\\IOException(code: 0): Failed to remove file \"/var/www/html/mautic/var/cache/pro~/translations/catalogue.en_US.qAY_2tt.php.meta\": unlink(/var/www/html/mautic/var/cache/pro~/translations/catalogue.en_US.qAY_2tt.php.meta): Permission denied at /var/www/html/mautic/vendor/symfony/filesystem/Filesystem.php:184)","command":"cache:clear","message":"Failed to remove file \"/var/www/html/mautic/var/cache/pro~/translations/catalogue.en_US.qAY_2tt.php.meta\": unlink(/var/www/html/mautic/var/cache/pro~/translations/catalogue.en_US.qAY_2tt.php.meta): Permission denied"} {"hostname":"vps","pid":1685}

I show the last lines of two files here

Can you make sure that var/cache does not contain any other files and folder other then:

  • ip_data/
  • languageList.txt
  • prod/
  • dev/
  • run/

Then move one dir up with cd .. and run the following:

chown -R www-data:root cache 
cd cache
find . type f -exec chmod 644 {} \;
find . type d -exec chmod 755 {} \;

and try again.

If that does not work can you share what happens when you go to mautic root dir and run (this is only temporary for debugging and should be addressed differently as its leaving your server exposed)

chown -R www-data: .

Does it work then? Give it a try and let me know.

change group to cache does not work.

I am not sure the second command gives what you expected. I don’t see change sin the group, they remain all www-data see output here. I did it any way, after that, the site is still not working (checked on different browsers)

Then I checked in var/logs/…php. no more messages after all these commands.

Basically I can install another instance from scratch. I don’t have data on this install, but I wish to clarify the problem just in case someone accidentally does what I did to remove the cache.

thank you much for your time.