The stream or file laravel.log could not be opened: Permission denied

13 May 2018

laravel-log-permission-denied

Problem:

After adding another view and route in Laravel, loading the page returns this error below the content:

The stream or file “/var/www/html/example.com/storage/logs/laravel.log” could not be opened: failed to open stream: Permission denied

This indicates that your web server is unable to open the indicated file, which is likely due to misconfigured permissions. Typically, Linux permissions for directories should be 755, and files should be 644. The exception in Laravel is bootstrap/cache and storage, which require the web server to have write permissions.

Solution:

From the terminal, in your document root, ensure your files and directories have to proper permissions.

sudo find . -type f -exec chmod 644 {} \;

sudo find . -type d -exec chmod 755 {} \;

Now adjust the permissions of bootstrap/cache and storage, giving the web server write permissions.

sudo chmod -R 775 bootstrap/cache/

sudo chmod -R 775 storage/

Reload you page and you should be error free!