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

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
    

You need to run one of the following:

  • sudo chmod -R 644 app/storage
  • sudo chmod -R 755 app/storage