Laravel 5 - Write to vendor directory

2020-06-03 05:17发布

问题:

Laravel 5 crashed after working for a while. Here's the error:

file_put_contents(/Library/WebServer/Documents/project/vendor/services.json): failed to open stream: Permission denied

in Filesystem.php line 74

I wonder why it's trying to write to the vendor directory?

回答1:

Try this artisan command

php artisan cache:clear


回答2:

(See update below!)

Some storage files used for caching were moved to a different location for Laravel v5.0.15.

Affected files:

  • services.json
  • compiled.php
  • routes.php

To quote one of the devs:

It makes more sense in vendor. This makes it more clear that the file is very specifically tied to the installed dependencies.

For more information and a discussion regarding the changes, see this commit.

Update: The maintainers changed this behavior after some discussion.

As of v5.1, all three files will be written to bootstrap/cache. If you're on v5.0.*, read on:

The vendor directory will not be written to unless it is actually writable.

Additionally, the method useStoragePathForOptimizations(bool) was added to Illuminate\Foundation\App and can be called from bootstrap/app.php. This sets the property $useStoragePathForOptimizations and determines whether the storage directory should be used for optimizations.

See the following two commits for more information:

  • Only use vendor if it is writable
  • Allow forcing of storage directory for opts


标签: laravel-5