By default, the Twig template cache appears to go into /files/php/twig.

I was wondering if it's possible to change this location? I use a shared file mount which is shared between multiple developers and my concern is that the Twig cache will be in competition with another developer.

Alternatively we can disable caching but this is not always appropriate.

1 Answer 1


Yes you can, put this in settings.php or any file loaded by it like settings.local.php:

  $settings['php_storage']['twig']['directory'] = '/path/to/tmp/folder';
  $settings['php_storage']['twig']['secret'] = $settings['hash_salt'];

Note that the directoy must exist already.

  • +1 upvoted question and answer. This solved a create directory/change its permissions failure error that arose in various locations in FileStorage.php, FileReadOnlyStorage.php, MTimeProtectedFastFileStorage.php, MTimeProtectedFileStorage.php. This occurred in my puphpet.com-based / vagrant provisioned virtualbox environment: Ubuntu 18.04 64bit LTS host / Ubuntu 16.04.4 guest. It's a limitation in that in the NFS shared folder, permissions cannot be changed in the guest VM. Commented Sep 22, 2018 at 12:18
  • So the solution is to move this twig caching path out of the shared folder, and into, say /tmp and setting its user ownership and group to www-user so that the PHP running from the web server process can access it sufficiently. The path I used was this: $settings['php_storage']['twig']['directory'] = '/tmp/sites-caching/php/'; in settings.local.php ensuring that settings.local.php is referenced from settings.php A twig directory is created off of this path by the code itself when it runs. Thank you very much, relief that I found a solution after a couple of hours. Commented Sep 22, 2018 at 12:22
  • Hopefully saves others from this difficultly. The outcome is that the warnings seen, e.g, "Warning: chmod(): Operation not permitted in Drupal\Component\PhpStorage\FileStorage->createDirectory() (line 168 of core/lib/Drupal/Component/PhpStorage/FileStorage.php). " do not now appear as they are now successful in execution. Commented Sep 22, 2018 at 12:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.