问题
I have setup Laravel homestead on a local OSX machine, everything seemed to be going smoothly until I tried to open example.app:8000 and got this error:
Error in exception handler: The stream or file "/home/vagrant/Code/example/app/storage/logs/laravel.log" could not be opened: failed to open stream: Protocol error in /home/vagrant/Code/example/bootstrap/compiled.php:8671
I followed the Laravel docs as well as a Laracast about setting up homestead, so I am not sure what would be causing this. I can see that /home/vagrant/Code/example/app/storage/logs/laravel.log
doesn't exist, but I assume that is something that should be created automatically?
回答1:
You need to run one of the following:
sudo chmod -R 644 app/storage
sudo chmod -R 755 app/storage
回答2:
All files and folders under app/storage
should be writable by you and group www-data (the webserver).
Error in exception handler: The stream or file "laravel/app/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied in laravel/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:77
If you get this error (or a similar error) in the browser when accessing your site, then the group www-data
can't write to app/storage
. If you get this error when you execute certain php artisan
commands, then you (the user) can't write to app/storage
. Therefore both you and the www-data group must have write permission.
To ensure the files and folders have the correct permissions:
Go to the root of your Laravel installation (where
composer.json
andartisan
live).Change the owning user and group, where
yourusername
is your username:sudo chown -R yourusername:www-data app/storage
This recursively (
-R
) sets the user:group owners toyourusername:www-data
in all files and folders fromapp/storage
onward.Add the write permission for both you and the
www-data
group:sudo chmod -R ug+w app/storage
This recursively (
-R
) adds (+
) the write flag (w
) to the user (u
) and group (g
) that own the files and folders fromapp/storage
onward.Additionally, some suggest you may need to flush the application cache.
php artisan cache:clear
Finally, you may want to regenerate Composer's autoload files.
composer dump-autoload
回答3:
As for me I had changed my storage permission with chmod -R 777 storage
and it's work well.
However, setting 777 permissions is incredibly dangerous and should not be done on any server other than your local machine.
I had checked for this configuration at here.
回答4:
You can do this by following steps
chmod -R 775 storage
which means
7 - Owner can write
7 - Group can write
5 - Others cannot write!
If your webserver is not running as Vagrant, it will not be able to write to it, so you have 2 options:
chmod -R 777 storage (do not do this)
or change the group to your webserver user, supposing it's www-data:
chown -R vagrant:www-data storage
回答5:
If changing the file permissions as described in the other answers didn't work and you're using CentOS 7 or RHEL then the issue may be a security program called selinux. I struggled with all kinds of permissions and groups before noticing user3670777 answer to Laravel 4: Failed to open stream: Permission denied
Hope this helps others.
回答6:
If All Above suggestions not working disable your selinux and try again
回答7:
im pretty new on laravel. May be I could not explain it in depth but that command fixed my problem.
chmod -R 777 storage/
来源:https://stackoverflow.com/questions/24055056/laravel-log-could-not-be-opened-failed-to-open-stream