JP Davy

JP Davy

How To Correct Permission Issues With Laravel Log Files

by JP Davy - December 5th, 2017

Laravel Forge makes managing servers a cinch. But you still have to know your way around the command line if anything goes wrong.

Today I upgraded php from 7.0 to 7.2 on my Linode server using Laravel Forge. Super easy: click a button in Forge, and it will upgrade it. But then sometimes there are issues. I reloaded my site to be greeted with error 500's everywhere. So I quickly set debug to true (probably nobody looks at this site anyway, so it doesn't much matter), and found out that there was a permission error for the app/storage/logs/laravel.log file.

The exact error was Error in exception handler: The stream or file "/app/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied in [...]

So, if you find yourself in this situation, it's pretty easy to fix.

  • SSH into your server.
    ssh {youruser}@{yourip_here}

  • cd {yourappname}

  • Note: Never set a directory to 777. Not even on dev. Just get used to doing it the proper way: change directory ownership instead. So set your current user that you are logged in with as owner and the webserver user (www-data, apache, ...) as the group.
    sudo chown -R {your_user}:www-data storage
    sudo chown -R {your_user}:www-data bootstrap/cache

  • Then set directory permissions
    chmod -R 775 storage
    chmod -R 775 bootstrap/cache

So there you go, that should fix it.