laravel.log could not be opened in append mode: Permission denied
The user PHP runs as cannot write to storage/logs/laravel.log. Fix the owner and group of storage and bootstrap/cache, never chmod 777.
- Message
- The stream or file ".../storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied
- Exception
- UnexpectedValueException
What it means
Laravel's file log, which runs on Monolog, tried to open storage/logs/laravel.log to add a line, and the operating system refused. The user PHP runs as may not write to that file, or may not create it in storage/logs. Monolog throws an UnexpectedValueException and adds the message it failed to write after "The exception occurred while attempting to log:". Laravel then tries to log that failure and fails again, so the message repeats, and the last of those lines holds the error you were originally trying to log.
Why it happens
- The log file belongs to another user. Whoever writes the first line creates the file and owns it. When a cron job, a queue worker or an
artisancommand run as root or as your deploy user createslaravel.log, the file gets permission0644, which the docs list as the default for thesingleanddailychannels. The web server's PHP user can read it but not append to it. With thedailychannel this can return every day, because each day starts a new file. storagebelongs to the wrong user. After an upload or agit cloneas another user, PHP cannot create files instorage/logsat all, and the message is the same. The deployment docs say Laravel must be able to write tostorageandbootstrap/cache.
How to fix it
See who owns the files, and compare with the user your PHP-FPM workers run as:
ls -l storage/logs
ps aux | grep php-fpm
Give the files to your deploy user and the web server's group, let that group write, and make new files inherit the group. This example assumes a deploy user and the www-data group:
sudo chown -R deploy:www-data storage bootstrap/cache
sudo chmod -R ug+rwX storage bootstrap/cache
sudo find storage bootstrap/cache -type d -exec chmod g+s {} +
Then let Laravel create log files that the group can write, with the permission option of the channel. This excerpt shows the one key to add to your channel in config/logging.php:
'single' => [
// ...
'permission' => 0664,
],
Run the scheduler and queue workers as the same user as the site, not as root, so they never create files the site cannot write.
Do not fix this with chmod -R 777. It lets every user and every process on the server write to these folders. bootstrap/cache holds PHP files that Laravel loads on every request, so anyone who can write there can run code as your application.
Find it in production
The visitor gets a 500 response, but only on requests that write to the log. In a test, a page that logged nothing still answered 200, while a page that logged a line or threw an exception answered 500 with the plain "Server Error" page.
Only the log line is lost. laravel.log stops growing, but Laravel runs the handler's report callbacks before it writes the log line. An error tracker that hooks into the handler still receives the original exception, and then the UnexpectedValueException too. That holds unless the tracker buffers in a file cache under the same mis-owned storage directory. Ranetrace error monitoring receives what the handler reports. Its buffer uses the app's cache store, so with a file cache in that directory it fails as well.
Without a tracker, look for 500 responses in your web server's access log, and check when laravel.log last changed.
Reproduced on Laravel 13.45, PHP 8.5, 5 December 2026.
Related
Read more
Start monitoring today
Websites go down and code throws errors. Ranetrace tells you when it happens to yours, why it matters and what to do next.