Fix "laravel.log could not be opened in append mode: Permission denied"
The stream or file "/var/www/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied
- UnexpectedValueException: The stream or file "/var/www/html/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied
- The stream or file "/var/www/storage/logs/laravel-2026-11-27.log" could not be opened in append mode: Failed to open stream: Permission denied
- file_put_contents(/var/www/storage/framework/views/2f1a9c7e.php): Failed to open stream: Permission denied
- The /var/www/bootstrap/cache directory must be present and writable.
The web server’s PHP process (often www-data) is not allowed to write to storage/logs/laravel.log. Give the web server group to the storage and bootstrap/cache folders with chown, apply 775 to folders and 664 to files, and check SELinux on RHEL. Do not use chmod 777.
What this error means
Laravel constantly writes to storage (logs, sessions, cache, compiled Blade views) and to bootstrap/cache (package manifest, cached config and routes). These writes are made by the system user running PHP: www-data on Debian and Ubuntu, apache or nginx on RHEL. When the Monolog log handler opens laravel.log in append mode and the system refuses, it throws this UnexpectedValueException. The error often hides the original error, since Laravel cannot even log it. The file usually exists but belongs to another user, for example root after an artisan command run with sudo.
Common causes
- File created by another user:
php artisanor a cron job run as root or with your SSH account createslaravel.log(or the day’s log with thedailychannel) thatwww-datacan no longer modify. - Wrong owner after a deployment:
git clone, FTP upload,rsyncor archive extraction with a user other than the web server’s. - Docker with a bind mount: host files have your user’s UID, which differs from
www-data(UID 33) in the container. - SELinux enforcing (RHEL, Rocky, AlmaLinux, Fedora): Unix permissions are correct, but the
httpd_sys_content_tcontext only allows the web server to read.
Step-by-step fix
-
Identify the PHP user and the file owner
Compare the user running PHP-FPM or Apache with the owner of
laravel.log. If they differ, that is the cause.ps aux | grep -E 'php-fpm|apache2|httpd' | grep -v grep ls -la storage/logs -
Fix the owner and permissions
Keep your deploy user as the owner and give the web server group (here
www-data, adjust it) tostorageandbootstrap/cache. Folders in775, files in664, and thesetgidbit so new files inherit the group.cd /var/www sudo chown -R $USER:www-data storage bootstrap/cache sudo find storage bootstrap/cache -type d -exec chmod 2775 {} \; sudo find storage bootstrap/cache -type f -exec chmod 664 {} \; -
Run artisan and cron as the right user
Run commands that write to
storageas the web server user, and put the scheduler in its crontab rather than root’s.sudo -u www-data php artisan optimize:clear # crontab of www-data: sudo crontab -u www-data -e * * * * * cd /var/www && php artisan schedule:run >> /dev/null 2>&1 -
Robust option: ACLs
If several users write to
storage, default ACLs grantwww-datarights on every future file, whoever creates it. On Debian and Ubuntu, this needs theaclpackage.sudo setfacl -R -m u:www-data:rwX -m d:u:www-data:rwX storage bootstrap/cache -
RHEL / Rocky / Fedora: configure SELinux
If
getenforcereturnsEnforcing, allow web server writes on these folders only. Do not disable SELinux (setenforce 0): you would remove a protection from the whole server for a problem limited to two folders.getenforce sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/storage(/.*)?" sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/bootstrap/cache(/.*)?" sudo restorecon -Rv /var/www/storage /var/www/bootstrap/cache -
Docker: give the folders to
www-datain the imageIn the
Dockerfile, assignstorageandbootstrap/cacheto the PHP user. With a bind mount in development, align the container UID with yours instead (that is what Sail does withWWWUSER).COPY --chown=www-data:www-data . /var/www/html RUN chmod -R ug+rwX /var/www/html/storage /var/www/html/bootstrap/cache
Did this fix work for you?
Confirm it in one click: it will rise for the next developers stuck on the same error.
Keep it from coming back
- Never run
php artisanwithsudoon a server: usesudo -u www-dataor a deploy user that belongs to thewww-datagroup. - Add the
storageandbootstrap/cachepermission fix to your deployment script. - In production with Docker, send logs to
stderr(LOG_CHANNEL=stderr) so you no longer depend on a file on disk.
Frequently asked questions
Why not just run chmod -R 777 storage?
It lets any user or process on the server write there: a compromised service could change logs and sessions or drop files into storage/app/public, which is served publicly. Fix the owner and group instead.
Why does the error come back every night?
With the daily channel, a new laravel-YYYY-MM-DD.log file is created each day by the first process that writes. If that is a root cron job, root owns the file. Run cron as www-data or use default ACLs.
Which user does PHP run as on my server?
Debian and Ubuntu use www-data, RHEL and its derivatives apache or nginx. The user directive of the PHP-FPM pool (/etc/php/8.3/fpm/pool.d/www.conf on Ubuntu) is the reference.
Useful tools for this error
More PHP & Laravel errors
- Fix "419 Page Expired" in Laravel (CSRF token mismatch)
- Fix "Allowed memory size of 134217728 bytes exhausted" in PHP
- Fix "Target class [X] does not exist" and "Class not found" in Laravel
- Fix "SQLSTATE[HY000] [2002] Connection refused" in Laravel
- Fix "No application encryption key has been specified" in Laravel
- Fix "Your requirements could not be resolved to an installable set of packages" (Composer)
- Fix "Vite manifest not found at: public/build/manifest.json" in Laravel