Cms: Craft fails to install in Unix VM + Windows Host (filemutex)

Created on 4 Jun 2019  路  5Comments  路  Source: craftcms/cms

Description

I'm running craft inside the homestead box. The box will up correctly with everything installed, and when I navigate to http://localhost:8000/admin the setup wizard screen displays correctly and works fine, but every time I click through the final screen I get "Install Failed". phperrors.log says:

[03-Jun-2019 19:56:07 UTC] PHP Fatal error:  Uncaught yii\base\ErrorException: unlink(/home/vagrant/code/storage/runtime/mutex/a78d6a4ecc5877cd5617ca990a2be38b.lock): Text file busy in /home/vagrant/code/vendor/yiisoft/yii2/mutex/FileMutex.php:161
Stack trace:
#0 /home/vagrant/code/vendor/yiisoft/yii2/mutex/FileMutex.php(161): ::unlink()
#1 /home/vagrant/code/vendor/yiisoft/yii2/mutex/Mutex.php(88): yii\mutex\FileMutex->releaseLock()
#2 /home/vagrant/code/vendor/yiisoft/yii2/mutex/Mutex.php(57): yii\mutex\FileMutex->release()
#3 {main}
  thrown in /home/vagrant/code/vendor/yiisoft/yii2/mutex/FileMutex.php on line 161

which I believe is the same as #3879 and #3881. However, the fix for those issues (a custom FileMutex) has been deprecated in #3884. A yii variable 'isWindows' is apparently the way to correct this issue, but I haven't been able to find any documentation describing where/how to set this. I was following the up and running with Craft 3 tutorial as recommended in Developers New to Craft, but I have also googled it to no avail. Additionally, I couldn't find any mention of it anywhere in the documentation. I am new to craft and php, so perhaps I am missing something obvious.

The best solution would be for craft/yii to autodetect when it is running inside a VM, and use the host OS for this setting. I'm not sure this is possible, so the second-best solution is being able to override/force this setting.

Steps to reproduce

  1. Set up a windows host with vagrant, virtualbox, composer, etc.
  2. create a new craft project with composer create-project craftcms/craft .
  3. install homestead with the per-project installation: composer require laravel/homestead --dev and .\vendor\bin\homestead make
  4. run vagrant up to boot the box
  5. Once the box boots, open http://localhost:8000/admin and complete the craft install steps

Expected: craft installs correctly and redirects to the admin console.

Actual: an error message is displayed.

Additional info

  • Craft version: 3.1.28
  • PHP version: 7.3.6 (host) and 7.3.5 (guest)
  • Vagrant version: 2.2.4
  • Virtualbox version: 6.0.8
  • Homestead version: 7.20.0
  • Host OS: Windows 10 1809

Workaround:

The install is completed successfully if vagrant uses SMB for the file sharing instead of the default (virtualbox). However, this is unsatisfactory because it requires admin privileges.

Most helpful comment

Thank you, I can confirm that works!

All 5 comments

A yii variable 'isWindows' is apparently the way to correct this issue, but I haven't been able to find any documentation describing where/how to set this.

From your Craft config/app.php file, you can use this to set the isWindows property of the FileMutex class to true.

return [
    'components' => [
        'mutex' => function() {
            $config = craft\helpers\App::mutexConfig();
            $config['isWindows'] = true;
            return Craft::createObject($config);
        },
    ],
];

Thank you, I can confirm that works!

Craft 3.4.5

I've just run into this when I switched my localhosting over to DDev.

After getting the site setup with DDev everything worked except for saving entries until I added the above.

Is this something that I will need to add to all sites going forward or will there be a an update that will address it in the future?

@CreateSean you'll have to add it as there's no reliable way for 1) Craft to detect that it's running in a VM/container and 2) that the host OS is Windows.

Okay, that's kind of what I was expecting. Thank you.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

benface picture benface  路  3Comments

darylknight picture darylknight  路  3Comments

davist11 picture davist11  路  3Comments

timkelty picture timkelty  路  3Comments

angrybrad picture angrybrad  路  3Comments