Php failed to write cache file

symfony2 : failed to write cache directory

For a GOOD and definite solution see the Setting up Permissions section in Installing and Configuring Symfony section :

  1. Use the same user for the CLI and the web server
  1. Using ACL on a system that supports chmod +a
$ rm -rf app/cache/* $ rm -rf app/logs/* $ HTTPDUSER=`ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1` $ sudo chmod +a "$HTTPDUSER 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 
$ HTTPDUSER=`ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1` $ sudo setfacl -R -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX app/cache app/logs $ sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX app/cache app/logs 

For Symfony 3 it would be:

$ HTTPDUSER=`ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1` $ sudo setfacl -R -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX var/cache var/logs $ sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX var/cache var/logs 
umask(0002); // This will let the permissions be 0775 // or umask(0000); // This will let the permissions be 0777 

Note that using the ACL is recommended when you have access to them on your server because changing the umask is not thread-safe.

Читайте также:  Лабораторные работы java наследование

Solution 2

Most likely it means that the directory and/or sub-directories are not writable. Many forget about sub-directories.

chmod -R 777 app/cache app/logs 

Symfony 3 directory structure

chmod -R 777 var/cache var/logs 

Additional Resources

Permissions solution by KPN University — additionally includes an screen-cast on installation.

Note: If you’re using Symfony 3 directory structure, substitute app/cache and app/logs with var/cache and var/logs .

Solution 3

If the folder is already writable so thats not the problem.

You can also just navigate to /www/projet_etienne/app/cache/ and manualy remove the folders in there (dev, dev_new, dev_old).

Make sure to SAVE a copy of those folder somewhere to put back if this doesn’t fix the problem

I know this is not the way it should be done but it worked for me a couple of times now.

Solution 4

You probably aborted a clearcache halfway and now you already have an app/cache/dev_old.

Try this (in the root of your project, assuming you’re on a Unixy environment like OS X or Linux):

Solution 5

I move the whole directory from my Windows installation to a unix production server and I got the same error. To fix it, I just ran these two lines in unix and everything started to run fine

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

Источник

Guide: Failed to write cache file “/var/www/myapp/app/cache/dev/classes.php” when clearing the cache

If you use Symfony or any other PHP framework, you might have encountered an issue while clearing the cache. The error message reads “Failed to write cache file “/var/www/myapp/app/cache/dev/classes.php” when clearing the cache”. This error usually occurs when the server does not have the right permissions to write to the cache files.

To fix this error, you can try the following solutions:

Solution 1: Set the right permissions

The first solution to this issue is to ensure that the server has the right permissions to write to the cache folder. You can use the `chmod` command to set the right permissions. Here’s an example:

$ chmod -R 777 /var/www/myapp/app/cache 

This command sets the permission of the cache folder to `777`, which means that everyone has full access to the folder. However, if you are using a shared hosting service, it is not recommended to set such broad permissions. Instead, you can set the permission to `775` or `755`, which gives the owner and group write permission.

Solution 2: Clear the cache manually

If the first solution does not work, you can try to clear the cache manually. You can do this by deleting the cache folder and then creating a new one. Here’s an example:

$ rm -rf /var/www/myapp/app/cache/* $ mkdir /var/www/myapp/app/cache $ chmod -R 775 /var/www/myapp/app/cache 

This command deletes everything in the cache folder and then creates a new one with the right permissions.

Solution 3: Check the ownership of the folder

If the first two solutions do not work, you can check the ownership of the cache folder. If the folder is owned by the wrong user or group, the server might not have the permission to write to it. Here’s an example:

$ chown -R www-data:www-data /var/www/myapp/app/cache 

This command changes the ownership of the cache folder to the `www-data` user and group, which is usually the user and group that runs the web server.

Solution 4: Disable opcache

If none of the above solutions work, you can try to disable opcache. Opcache is a caching mechanism built into PHP that can sometimes cause issues with cache clearing. Here’s how you can disable it:

This command disables opcache. You can then clear the cache without any issues.

By following these solutions, you can fix the “Failed to write cache file” error and ensure that your cache is cleared properly.

Источник

General developer forum

Hello, I have a real humdinger. I’m the Moodle Developer for a University and have been plagued by this «Exeption — Failed to write cache file» for a few months now. My stack is load balanced with 2 head ends and the moodle_data directory is on a beefy Dell Compellent NFS system. There are other Moodle instances on the stack but nothing shared. Other instances have different, older, versions and work fine.

This year our current Moodle instance is using 3.5.3.

Our cache is Couchbase (Memcached) that’s behind TwemProxy. Sessions are also in memcached but in it’s own seperate bucket (so we can purge if needed without losing sessions).

If I don’t purge Moodle Cache, Memcached and OPCache after 10-14 days then suddenly all users will get «Failed to write cache file». If a student hit’s refresh 3-5 times then sometimes it goes away. A few pages later and they’ll get that error again and again. As soon as I purge all caches the issues is gone for another week or two.

I’m having a heck of a time replicating this on our test stack and it’s extremely frustrating to all users, especially when they are writing exams/quizzes.

Why would this suddenly creep up and affect all users?

When I navigate into the localcache/mustache/[some number]/[theme name]/ folder I can see that file that failed to write.

From what I can see, and correct me if I’m wrong, as soon as the __MUSTACHE_ file is created that’s it. These cached files should not be re-written. right.

(4 hours later) So doing some more searching I found a similar issue: https://moodle.org/mod/forum/discuss.php?d=379587 and in this case this user had issues with language pack translations. We currently use es, fr and ja. Could this be a possible cause?

Any help or advice would be greatly appreciated.

Источник

Failed to write cache file «/var/www/myapp/app/cache/dev/classes.php» when clearing the cache

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

sudo setfacl -R -m u:apache:rwX -m u:`whoami`:rwX app/cache app/logs sudo setfacl -dR -m u:apache:rwX -m u:`whoami`:rwX app/cache app/logs 

(where apache is your HTTPD user)

Solution 2

Well, I’m using setfacl to avoid that issues but I still having problems. I’m working on a standard user directory so this do not work for me:

APACHEUSER=`ps aux | grep -E '[a]pache|[h]ttpd' | grep -v root | head -1 | cut -d\ -f1` sudo setfacl -R -m u:$APACHEUSER:rwX -m u:`whoami`:rwX app/cache app/logs sudo setfacl -dR -m u:$APACHEUSER:rwX -m u:`whoami`:rwX app/cache app/logs 

If you too, do this: (as privileged user if necessary of course )

sudo rm -rf app/cache app/logs 

Then as NORMAL user create both directories and then apply the commands below as NORMAL user too (without sudo):

exit (from root if necessary) mkdir app/cache app/logs APACHEUSER=`ps aux | grep -E '[a]pache|[h]ttpd' | grep -v root | head -1 | cut -d\ -f1` setfacl -R -m u:$APACHEUSER:rwX -m u:`whoami`:rwX app/cache app/logs setfacl -dR -m u:$APACHEUSER:rwX -m u:`whoami`:rwX app/cache app/logs 

Note: remember that there are two spaces between -d\ and -f1

Omega

Updated on January 08, 2020

Comments

I have installed Symfony 2.0.7 on Ubuntu 11.10. I have this problem: I changed the permissions of the cache e logs directories using the following commands:

chmod 777 -R cache chmod 777 -R logs 

Clearing the cache for the dev environment with debug true permissions of cache/dev change to 755 and symfony cannot write in that: RuntimeException: Failed to write cache file «/var/www/myapp/app/cache/dev/classes.php». in /var/www/myapp/app/bootstrap.php.cache line 1079 at ClassCollectionLoader::writeCacheFile() in /var/www/myapp/app/bootstrap.php.cache line 1017 at ClassCollectionLoader::load() in /var/www/myapp/app/bootstrap.php.cache line 682 at Kernel->loadClassCache() in /var/www/myapp/web/app_dev.php line 23

Источник

Оцените статью