Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I had an issue with twig after upgrading to 8.7.0-beta1
User warning: mkdir(): Permission Denied in Drupal\Component\PhpStorage\FileStorage->createDirectory() (line 174 of core/lib/Drupal/Component/PhpStorage/FileStorage.php).
Drupal\Component\PhpStorage\FileStorage->createDirectory('/tmp/twig', 511) (Line: 121)
Drupal\Component\PhpStorage\FileStorage->ensureDirectory('/tmp/twig') (Line: 66)
Drupal\Component\PhpStorage\MTimeProtectedFastFileStorage->save('5ca0b23c28013_status-messages.html.twig_3_7GEvvubFlSDBFsuJwHKQ4so', '<?php
I have the following in settings.php:
$settings['php_storage']['twig'] = array(
'directory' => DRUPAL_ROOT . '/../.php',
);
This should change the twig cache dir, but it was still throwing the above error.
I also tried changing the default tmp dir in file system settings to no avail.
Comments
Comment #2
cilefen CreditAttribution: cilefen as a volunteer commentedYes, that's weird. \Drupal\Core\PhpStorage\PhpStorageFactory::get hasn't changed in recent releases or in this release. I think debugging is needed in \Drupal\Core\Template\TwigPhpStorageCache::storage to see what \Drupal\Core\PhpStorage\PhpStorageFactory::get returned.
Comment #3
plachMarking the tracking issue as parent to keep track of issues found in the scope of the beta testing program.
Comment #4
larowlanIs this happening in a CI build @kim.pepper? If so, do you mkdir on /tmp/twig first?
Comment #5
kim.pepperThis was happening on both a local and CI build. I manually created that directory, set write permissions and the error went away.
Comment #6
MichelleI run into this issue on my local installs quite a lot so would love to have a solution. Unfortunately, I have no suggestions but wanted to chime in as another victim of this issue.
Comment #7
leymannx#5 seems to work. But only until you flush the cache again.
Comment #8
leymannxSetting
$settings['php_storage']['twig']['directory'] = 'sites/default/files';
in my settings.local.php fixes it for me now.Before that I always had to manually create a
twig
directory insidesites/default/files/php
. With the setting above in my settings.local.php the twig directory now gets created directly insidesites/default/files
and it also persists after cache flush.Comment #9
leymannxAy, rejoice too soon. Flushing cache from the UI is OK. This directory gets deleted and recreated. But flushing cache via Drush deletes this directory and it doesn't get recreated. And the error occurs again.
Comment #10
leymannxReally weird. Setting
$settings['php_storage']['twig']['directory'] = '../../twig';
at least prevents the error being triggered. But I don't see where else all the stuff that used to be inside this folder gets created now. It's just gone. I think this shouldn't be considered a valid fix. But since this only happens in my local dev environment I'm fine with that.Comment #11
ivan ojiamboI ran into the same error today, creating the twig folder inside "sites/default/files/php" as suggested by leymannx fixed the issue.
Comment #12
ivanSB@drupal.orgI didn't even modified manually anything in settimgs.php, I even checked if in any place php_storage is referenced in drupal code and I'm experiencing similar problems.
I'm installing via this script
https://github.com/Ivan-SB/drupal_build
What seems to temporarely fix this is
drush cr
#1 [internal function]: _drupal_error_handler()"
#2 /var/www/html/test/drupal8/core/lib/Drupal/Component/PhpStorage/FileStorage.php(145): trigger_error()"
#3 /var/www/html/test/drupal8/core/lib/Drupal/Component/PhpStorage/FileStorage.php(126): Drupal\Component\PhpStorage\FileStorage->createDirectory()"
#4 /var/www/html/test/drupal8/core/lib/Drupal/Component/PhpStorage/FileStorage.php(95): Drupal\Component\PhpStorage\FileStorage->createDirectory()"
#5 /var/www/html/test/drupal8/core/lib/Drupal/Component/PhpStorage/MTimeProtectedFastFileStorage.php(66): Drupal\Component\PhpStorage\FileStorage->ensureDirectory()"
#6 /var/www/html/test/drupal8/core/lib/Drupal/Core/Template/TwigPhpStorageCache.php(111): Drupal\Component\PhpStorage\MTimeProtectedFastFileStorage->save()"
#7 /var/www/html/test/drupal8/vendor/twig/twig/src/Environment.php(487): Drupal\Core\Template\TwigPhpStorageCache->write()"
#8 /var/www/html/test/drupal8/vendor/twig/twig/src/Environment.php(445): Twig\Environment->loadClass()"
#9 /var/www/html/test/drupal8/core/themes/engines/twig/twig.engine(64): Twig\Environment->loadTemplate()"
#10 /var/www/html/test/drupal8/core/lib/Drupal/Core/Theme/ThemeManager.php(384): twig_render_template()"
#11 /var/www/html/test/drupal8/core/lib/Drupal/Core/Render/Renderer.php(431): Drupal\Core\Theme\ThemeManager->render()"
#12 /var/www/html/test/drupal8/core/lib/Drupal/Core/Render/Renderer.php(200): Drupal\Core\Render\Renderer->doRender()"
#13 /var/www/html/test/drupal8/core/lib/Drupal/Core/Template/TwigExtension.php(501): Drupal\Core\Render\Renderer->render()"
#14 /var/www/html/test/drupal8/vendor/twig/twig/src/Environment.php(497) : eval()'d code(102): Drupal\Core\Template\TwigExtension->escapeFilter()"
#15 /var/www/html/test/drupal8/vendor/twig/twig/src/Template.php(455): __TwigTemplate_41bd370b7d861960ca444280e3fca2558e63d6c52c0b53058e2e7c332a9d33bc->doDisplay()"
#16 /var/www/html/test/drupal8/vendor/twig/twig/src/Template.php(422): Twig\Template->displayWithErrorHandling()"
#17 /var/www/html/test/drupal8/vendor/twig/twig/src/Template.php(434): Twig\Template->display()"
#18 /var/www/html/test/drupal8/core/themes/engines/twig/twig.engine(64): Twig\Template->render()"
#19 /var/www/html/test/drupal8/core/lib/Drupal/Core/Theme/ThemeManager.php(384): twig_render_template()"
#20 /var/www/html/test/drupal8/core/lib/Drupal/Core/Render/Renderer.php(431): Drupal\Core\Theme\ThemeManager->render()"
Comment #15
RainbowGiantSquid CreditAttribution: RainbowGiantSquid commenteds
Comment #18
na.karimi CreditAttribution: na.karimi as a volunteer commentedhttps://www.drupal.org/project/drupal/issues/3044682#comment-13503198
Thanks @leymannx that works for me by adding `$settings['php_storage']['twig']['directory'] = 'sites/default/files';` to the settings.
Comment #19
cilefen CreditAttribution: cilefen as a volunteer commentedI think my questions posed in #2 need answers for us to get anywhere with this one.
Comment #22
quietone CreditAttribution: quietone at PreviousNext commentedI pinged @kim.pepper about this in #bugsmash. He responded saying that the problem no longer exists and expected it was his env set at the time. It was pointed out that the questions asked 4 years need to be answered to make any progress here. Those questions remain unanswered.
Therefore, I am closing this.
If you are experiencing this problem on a supported version of Drupal reopen the issue, by setting the status to 'Active', and provide complete steps to reproduce the issue (starting from "Install Drupal core").
Thanks!