In my case I had this error after running:
php -d memory_limit=-1 ./bin/console cache:clear --env=prod
The solution was to rerun the command while being logged as `www-data` user.