Clearing cache in Symfony 5

Viewed 5892

How to clear cache in Symfony 5?

Official docs at https://symfony.com/doc/current/cache.html#clearing-the-cache says that we should use the php bin/console cache:pool:clear cache.global_clearer command. However this does not clear cache because I was stuck for 20 minutes thinking why some files aren't refreshed.

Then I went with old way using php bin/console cache:clear --env prod however this breaks permissions all the time and I have to run sudo chmod 777 -R var/cache each time.

I am on Centos7.

1 Answers

Is the user you use to clear the cache is the same as the php user ?

Your chmod 777 works because of the last 7. This is not a best practice.

Here is an exemple with Apache & PHP-FPM :

[php-fpm@myserver myproject]$ ll var/cache/prod/
total 756
-rw-rw----   1 php-fpm www   5688  2 déc.  15:33 annotations.map
-rw-rw----   1 php-fpm www 529129  2 déc.  15:33 annotations.php
drwxrwx---   2 php-fpm www   4096  2 déc.  15:33 ContainerEKUR7PE
drwxrwx---   3 php-fpm www   4096  2 déc.  15:33 doctrine
drwxrwx---  11 php-fpm www   4096  2 déc.  15:33 pools
-rw-rw----   1 php-fpm www    100  2 déc.  15:33 serialization.php
-rw-rw----   1 php-fpm www    761  2 déc.  15:33 srcApp_KernelProdContainer.php
-rw-rw----   1 php-fpm www      0  2 déc.  15:33 srcApp_KernelProdContainer.php.lock
-rw-rw----   1 php-fpm www 103727  2 déc.  15:33 srcApp_KernelProdContainer.php.meta
-rw-rw----   1 php-fpm www  34142  2 déc.  15:33 srcApp_KernelProdContainer.preload.php
drwxrwx---   2 php-fpm www   4096  2 déc.  15:33 translations
drwxrwx--- 114 php-fpm www   4096  2 déc.  15:33 twig
-rw-rw----   1 php-fpm www  12520  2 déc.  15:33 UrlGenerator.php
-rw-rw----   1 php-fpm www   5438  2 déc.  15:33 UrlGenerator.php.meta
-rw-rw----   1 php-fpm www  14979  2 déc.  15:33 UrlMatcher.php
-rw-rw----   1 php-fpm www   5438  2 déc.  15:33 UrlMatcher.php.meta
-rw-rw----   1 php-fpm www   5968  2 déc.  15:33 validation.php
-rw-rw----   1 php-fpm www   3240  2 déc.  15:33 webpack_encore.cache.php

Here is my umask :

[php-fpm@myserver myproject]$ umask
0007

And here is my user groups :

[php-fpm@myserver myproject]$ id
uid=996(php-fpm) gid=1000(www) groupes=1000(www),994(php-fpm)

My server is a CentOS 7 too.

Related