How To Correct Permission Issues With Laravel Log Files

by JP Davy - Tuesday, December 5, 2017

Today I upgraded php from 7.0 to 7.2 on a Linode server using Laravel Forge. Super easy: click a button in Forge, and it will upgrade it. But then sometimes there are issues...

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.

  1. SSH into your server.
    ssh {your_user}@{your_ip_here}
  2. cd {your_app_name}
  3. 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
  4. Then set directory permissions
    chmod -R 775 storage
    chmod -R 775 bootstrap/cache

So there you go, that should fix it.