Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"laravel.log" could not be opened: failed to open stream [duplicate]

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?

like image 858
Josh Mountain Avatar asked Jun 05 '14 08:06

Josh Mountain


1 Answers

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:

  1. Go to the root of your Laravel installation (where composer.json and artisan live).

  2. 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 to yourusername:www-data in all files and folders from app/storage onward.

  3. 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 from app/storage onward.

  4. Additionally, some suggest you may need to flush the application cache.

    php artisan cache:clear
    
  5. Finally, you may want to regenerate Composer's autoload files.

    composer dump-autoload
    
like image 95
Daniel A.A. Pelsmaeker Avatar answered Sep 20 '22 04:09

Daniel A.A. Pelsmaeker