Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony - RuntimeException: Failed to write cache file

I am having trouble getting the permissions correct. I am trying to get it running in a local environment on my Mac via XAMPP.

I have tried the following:

  • Doing the unmask
  • Setting The Permissions
  • Clearing the cache via php app/console cache:clear
like image 718
Jess McKenzie Avatar asked Aug 30 '12 06:08

Jess McKenzie


2 Answers

rm -rf app/cache/*
rm -rf app/logs/*

sudo chmod +a "www-data allow delete,write,append,file_inherit,directory_inherit" app/cache app/logs
sudo chmod +a "`whoami` allow delete,write,append,file_inherit,directory_inherit" app/cache app/logs

Make sure you replace the www-data user with the user your web server runs as. Find out which user your web server runs as by running the command:

ps aux | grep http

Or

ps aux | grep apache

You may also need to enable ACL. See the Installation docs for more information, and see this page for information on ACL.

When running Symfony from the command line, cached files/directories are created by the user you're logged in as - in your case, "jess". When running the web page in your browser, they're created by the web server user - in your case, the user "nobody". Your user does not have access to modify files and dirs created by the web server, and vice versa.

Changing your web server to run as the same user as your login is not the ideal solution as it's not a very secure option, and you are still going to have the same problem when you put your site on another server.

The solution is to ensure you've followed the Setting Up Permissions section of the installation docs at http://symfony.com/doc/current/book/installation.html.

Make sure you rm -rf the contents of the folder, and not just php app/console cache:clear, as the symfony clear cache command will create dirs/files, which are still not writable by your web server.

like image 133
emarref Avatar answered Sep 28 '22 20:09

emarref


In general you should run your webserver from the same user as php5-cli. And the folder in which your project is located should have all permissions for this user.

You should either change user for project directory or simply chmod -R 777 app/cache and chmod -R 777 app/logs

like image 20
Vitalii Zurian Avatar answered Sep 28 '22 20:09

Vitalii Zurian