I'm seeing errors like these in the Apache error log immediately after deployment and there are HTTP 500 errors:

PHP Fatal error: Uncaught RuntimeException: Failed to write cache file "/var/www/html/app/tmp/twig_cache/6d/6d9137e2293cd0c967ee8ce214a07535e605a8a487340c1fcebb231ae2ef9317.php".

/var/www/html/app is a symlink to /var/www/app/4.0.0 (outside if the document root). What I'm doing now is preparing the new version in a directory and running this command in the html directory to go live:

ln --symbolic --directory --force --no-target-directory ../app/4.1.0 app

This worked for a few versions but recently the errors have started to occur, most likely from people who already had the site open prior to the update.

A solution would be to restart the Apache server via systemctl restart httpd but it can take almost a minute and a half for systemd to restart it, which is problematic during business hours. Apache restarts very quickly on the QA environment so again I assume the delay is caused by waiting for open connections to terminate.

Can someone suggest a better way to deploy the application to avoid this problem?


A solution would to to restart the Apache server

If that fixes the error you describe then there is something very wrong with the operating system.

Failed to write...


  • a permissions issue
  • a locking issue
  • a missing directory

You have the source code. You can see what is in the filesystem. You can also see the full text of the error. If this does not include the file and line number where the error occurs then you can instrument your code to capture this.

Typing the error message into Google is often a good place to start. If you had you would have seen many descriptions of at least 2 of the above manifesting for other users. And in some cases descriptions of how they fixed the problems

Certainly using symlinks has a performance and capacity impact. As long as you told Apache to follow symlinks it does not have a performance impact.

  • The code that is causing the error is the Twig template cache. The directory is present and there is no difference in permissions for this directory on the new and old versions. In fact there are folders being created by the apache user in /var/www/html/app/tmp/twig_cache/, which is expected, but there is no folder named 6d like shown in the error message. – rink.attendant.6 Jan 26 '18 at 23:49
  • Sounds like you've nearly solved the problem: look at the code, why is the directory not being created? – symcbean Jan 26 '18 at 23:51
  • The code appears to not create the directory if it the directory path passes is_dir and is_writable. If it had tried to create a directory and failed, a different error message would have appeared. – rink.attendant.6 Jan 26 '18 at 23:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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