Jess McKenzie
Jess McKenzie

Reputation: 8385

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:

Upvotes: 11

Views: 22299

Answers (4)

user1853984
user1853984

Reputation: 369

I got this error and I tried all these tips without success...

I eventually find the solution by desactivating seLinux. To do it, edit file "/etc/selinux/config" and replace SELINUX value by

SELINUX=disabled

Upvotes: -1

emarref
emarref

Reputation: 1311

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.

Upvotes: 23

Elnur Abdurrakhimov
Elnur Abdurrakhimov

Reputation: 44841

See the Setting up Permissions sidenote in the Configuration and Setup section. Use the ACL approach with setfacl.

Upvotes: 1

Vitalii Zurian
Vitalii Zurian

Reputation: 17976

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

Upvotes: 6

Related Questions