Symfony2: Could not create cache directory

I had to use

app/console cache:clear command 

to solve the problem when creating the object.

Now I can not load my homepage:

  http://localhost/projet_etienne/web/app_dev.php 

He says:

RuntimeException: Failed to write cache file "/var/www/projet_etienne/app/cache/dev/classes.php".

I'm not very good at this cache business!

In my app/cache folder, I got the dev folder, dev_new , a dev_old . This is normal?

 app/console cache:clear 

generates, by the way, a:

[ErrorException] Warning: rename (/ var / www / projet_etienne / app / cache / dev, / var / www / projet_etien
ne / app / cache / dev_old): the directory is not empty in / var / www / projet _etienne / vendo
r / Symfony / Symfony / SRC / Symfony / Bundle / FrameworkBundle / Command / CacheClearComm
and .php line 77

Please, help!

+59
symfony
Nov 03 '12 at 17:48
source share
9 answers

For a GOOD and specific solution, see Setting up Permissions in Installing and Configuring Symfony :

Permission settings

One common problem when installing Symfony is that the application / cache and the app / logs directories must be writable by both the web server and the command line user. On a UNIX system, if your web server user is different from your command line user, you can try one of the following solutions.

  1. Use the same user for CLI and web server

In development environments, it is common practice to use the same UNIX user for the CLI and the web server because it avoids any of these resolution problems when setting up new projects. This can be done by editing the configuration of your web server (for example, usually httpd.conf or apache2.conf for Apache) and setting it as a user in the same way as your CLI user (for example, for Apache, update the user and group values).

  1. Using ACLs on a system supporting chmod + a

Many systems allow you to use the chmod + a command. Try again, and if you get an error, try the following method. This uses the command to try to determine the user of your web server and set it as HTTPDUSER:

 $ 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 
  1. Using ACLs on a system that does not support chmod + a

Some systems do not support chmod + a, but support another utility called setfacl. You may need to enable ACL support on your partition and install setfacl before using it (as is the case with Ubuntu). This uses the command to try to determine the user of your web server and set it as HTTPDUSER:

 $ 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 -mu:"$HTTPDUSER":rwX -mu:'whoami':rwX app/cache app/logs $ sudo setfacl -dR -mu:"$HTTPDUSER":rwX -mu:'whoami':rwX app/cache app/logs 

For Symfony 3, it will 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 -mu:"$HTTPDUSER":rwX -mu:'whoami':rwX var/cache var/logs $ sudo setfacl -dR -mu:"$HTTPDUSER":rwX -mu:'whoami':rwX var/cache var/logs 

If this does not work, try adding the -n option.

  1. Without using ACL

If none of the previous methods work for you, change umask so that the cache and log directories are writeable in a group or write all over the world (depending on whether the web server user and the command line user are in that same group or not). To achieve this, put the following line at the beginning of the app / console, web / app.php and web / app_dev.php files:

 umask(0002); // This will let the permissions be 0775 // or umask(0000); // This will let the permissions be 0777 

Please note that using ACLs is recommended when you have access to them on your server because modifying umask is not thread safe.

http://symfony.com/doc/current/book/installation.html#checking-symfony-application-configuration-and-setup

source: Failed to write cache file "/var/www/myapp/app/cache/dev/classes.php" while clearing cache

+95
Feb 25 '13 at 15:17
source share

Most likely, this means that the directory and / or subdirectories are not writable. Many forget about subdirectories.

Symfony 2

 chmod -R 777 app/cache app/logs 

Symfony 3 Directory Structure

 chmod -R 777 var/cache var/logs 

Additional resources

Permissions for Symfony Solution (mentioned earlier).

Resolution for KPN University Solutions - additionally includes screen installation during installation.

Note. If you use the symfony 3 directory structure, replace app/cache and app/logs with var/cache and var/logs .

+22
Jun 17 '14 at 19:20
source share

If the folder is already writable, so this is not a problem.

You can also just go to /www/projet_etienne/app/cache/ and manually delete the folders there (dev, dev_new, dev_old).

Be sure to save a copy of this folder somewhere to return it if this does not fix the problem.

I know that this is not how it should be done, but it worked for me a couple of times.

+17
Nov 03 '12 at 20:59
source share

You probably interrupted clearcache halfway, and now you already have the / cache / dev _old application.

Try this (at the root of your project if you are in a Unixy environment such as OS X or Linux):

rm -rf app/cache/dev*

+12
Nov 14 '12 at 10:29
source share

You may have forgotten to change app / log app / log permissions

I use ubuntu so

 sudo chmod -R 777 app/cache sudo chmod -R 777 app/logs sudo setfacl -dR -mu::rwX app/cache app/logs 

Hope this helps.

+8
Aug 03 '14 at 7:32
source share

I transferred the entire directory from my Windows installation to the Unix production server, and I got the same error. To fix this, I just ran these two lines on Unix and everything started working fine

 rm -rf app/cache/* rm -rf app/logs/* 
+1
Feb 10 '14 at 19:53
source share

i completed:

 ps aux | grep apache 

and got something like this:

 root 28147 0.0 5.4 326336 27024 ? Ss 20:06 0:00 /usr/sbin/apache2 -k start www-data 28150 0.0 1.3 326368 6852 ? S 20:06 0:00 /usr/sbin/apache2 -k start www-data 28151 0.0 4.4 329016 22124 ? S 20:06 0:00 /usr/sbin/apache2 -k start www-data 28152 0.1 6.0 331252 30092 ? S 20:06 0:00 /usr/sbin/apache2 -k start www-data 28153 0.0 1.3 326368 6852 ? S 20:06 0:00 /usr/sbin/apache2 -k start www-data 28154 0.0 1.3 326368 6852 ? S 20:06 0:00 /usr/sbin/apache2 -k start www-data 28157 0.0 1.3 326368 6852 ? S 20:06 0:00 /usr/sbin/apache2 -k start user 28297 0.0 0.1 15736 924 pts/4 S+ 20:12 0:00 grep --color=auto apache 

therefore, my user without access turned out to be www-data , so I ran the commands:

 sudo chown -R www-data app/cache sudo chown -R www-data app/logs 

and he solved the access error.

Never use an insecure 777 to solve specific access problems:

 sudo chmod -R 777 app/cache sudo chmod -R 777 app/logs 
+1
Jan 25 '17 at 17:20
source share

if the symfony version is less than 2.8

 sudo chmod -R 777 app/cache/* 

if the symfony version is greater than or equal to 3.0

 sudo chmod -R 777 var/cache/* 

0
Jun 05 '18 at 14:15
source share

Just use this acl cmd, next time the files inside var are created, it will have r / w / x permission for www-data user.

 cd var rm -rf * cd .. setfacl -d -mu:www-data:rwx var 

Cmd explanation:

 setfacl -> Set acl command -d -> default behavior -m -> modify u:www-data: -> for user rwx -> adding permissions var -> on the folder 
0
Aug 08 '19 at 10:52 on
source share



All Articles