Short answer
Use sudo: sudo rm -r ./storage/framework/cache
Long answer
Make sure that all processes that write to the cache use the same user (and not only belong to the same group), because it turns out that Laravel writes cache files with privileges, something like lines 0755, which restricts the record to the owner.
If you, like me, you use a different user for each of them:
- PHP process
- Artisan CLI
- Artisan through the supervisor (for assignments)
As a result, you get files belonging to different users, and cannot be written or deleted by other users, even if they belong to the desired group (for example, www-data).
Hopefully someone finds a way to set the new file cache privileges in Larvel to about 0775. It would be nice if he just inherited from his parent.
Side note
This for me also caused a problem with Cache::remember() between the supervisor process and the PHP process, so I got put_file_contents errors because the cached files could not be written by different users.
Original answer
I had the same problem and in my case the files were not deleted because they were write protected. When I deleted them manually using rm -r ./storage/framework/cache , did I get a warning rm: descend into write-protected directory 'cache/c5'? . I was not going to enter yes for each file in the cache, so I ran the same command as sudo and worked without a hitch sudo rm -r ./storage/framework/cache .
This answers the question of why they are not deleted by Artisan cache:clear , and running rm is a fairly simple job; although it does not solve the problem of why files are written as write protected.
After deleting the cache, Laravel again creates the cache as write-protected. This means that this is probably a bug, and requires someone to send a bug report to Laravel developers. Since the workaround is trivial, I will leave it for someone else.