symfonyvirtualbox

Virtualbox shared + Symfony = "Text file busy"


I have a Linux virtual machine (Ubuntu) and created a Shared directory (/var/www/MYWEBSITE)

Installed Symfony there, and now I face a problem when it tries to clear its cache: "Operation not permitted" or "Text file busy"

Calling "bin/console cache:clear" from terminal gives the same error

"sudo bin/console cache:clear" - same error, so I think it's not a permission issue

Deleting the cache files or the whole directory manually (i.e. from file manager) works fine for every user (tried root/user/www-data)

Looks like this issue is related to Virtualbox file system, but I'm not sure


Solution

  • Found the solution: https://reddingitpro.com/2022/02/10/vagrant-symfony-log-files/

    Because of the way Vagrant maps these folders between the virtual environment and the physical Windows host, there can be significant lag

    The easiest way to handle this is to move the cache/log dirs into another (non-shared) location for DEV mode:

    Edit the Symfony kernel class to use the new path:

    public function getCacheDir(): string
    {
        if($this->environment=="dev"){
            return '/var/log/dev/cache'; //magic happens here
    
        }
        return dirname(__DIR__).'/var/'.$this->environment.'/cache';
    }
    
    public function getLogDir(): string
    {
        if($this->environment=="dev"){
            return '/var/log/dev/log'; //and here
        }
        return dirname(__DIR__).'/var/'.$this->environment.'/log';
    }
    

    This code will specifically use the new /var/log/dev subdirectory for both cache and log files exclusively while the Symfony environment is configured to “dev”. Otherwise it will use the default location, such as in production where hopefully you are not running it in a virtual box setup