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

kim.pepper created an issue. See original summary.

cilefen’s picture

Yes, 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.

plach’s picture

Marking the tracking issue as parent to keep track of issues found in the scope of the beta testing program.

larowlan’s picture

Status: Active » Postponed (maintainer needs more info)

Is this happening in a CI build @kim.pepper? If so, do you mkdir on /tmp/twig first?

kim.pepper’s picture

Status: Postponed (maintainer needs more info) » Active

This was happening on both a local and CI build. I manually created that directory, set write permissions and the error went away.

Michelle’s picture

I 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.

leymannx’s picture

#5 seems to work. But only until you flush the cache again.

leymannx’s picture

Setting $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 inside sites/default/files/php. With the setting above in my settings.local.php the twig directory now gets created directly inside sites/default/files and it also persists after cache flush.

leymannx’s picture

Ay, 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.

leymannx’s picture

Really 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.

ivan ojiambo’s picture

I ran into the same error today, creating the twig folder inside "sites/default/files/php" as suggested by leymannx fixed the issue.

ivanSB@drupal.org’s picture

I 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()"

Version: 8.7.0-beta1 » 8.7.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.

Version: 8.7.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Branches prior to 8.8.x are not supported, and Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

RainbowGiantSquid’s picture

s

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev
na.karimi’s picture

https://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.

cilefen’s picture

Status: Active » Postponed (maintainer needs more info)

I think my questions posed in #2 need answers for us to get anywhere with this one.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Status: Postponed (maintainer needs more info) » Closed (works as designed)
Issue tags: +Bug Smash Initiative

I 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!