Skip to content
FR
  1. LuzineDebug
  2. PHP & Laravel
  3. The stream or file "/var/www/storage/logs/larave…
PHP & Laravel Intermediate ≈ 10 min to fix

Fix "laravel.log could not be opened in append mode: Permission denied"

Error message
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.
In short

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.

Be the first to confirm this fix

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

  1. File created by another user: php artisan or a cron job run as root or with your SSH account creates laravel.log (or the day’s log with the daily channel) that www-data can no longer modify.
  2. Wrong owner after a deployment: git clone, FTP upload, rsync or archive extraction with a user other than the web server’s.
  3. Docker with a bind mount: host files have your user’s UID, which differs from www-data (UID 33) in the container.
  4. SELinux enforcing (RHEL, Rocky, AlmaLinux, Fedora): Unix permissions are correct, but the httpd_sys_content_t context only allows the web server to read.

Step-by-step fix

  1. 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.

    bash
    ps aux | grep -E 'php-fpm|apache2|httpd' | grep -v grep
    ls -la storage/logs
  2. Fix the owner and permissions

    Keep your deploy user as the owner and give the web server group (here www-data, adjust it) to storage and bootstrap/cache. Folders in 775, files in 664, and the setgid bit so new files inherit the group.

    bash
    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 {} \;
  3. Run artisan and cron as the right user

    Run commands that write to storage as the web server user, and put the scheduler in its crontab rather than root’s.

    bash
    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
  4. Robust option: ACLs

    If several users write to storage, default ACLs grant www-data rights on every future file, whoever creates it. On Debian and Ubuntu, this needs the acl package.

    bash
    sudo setfacl -R -m u:www-data:rwX -m d:u:www-data:rwX storage bootstrap/cache
  5. RHEL / Rocky / Fedora: configure SELinux

    If getenforce returns Enforcing, 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.

    bash
    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
  6. Docker: give the folders to www-data in the image

    In the Dockerfile, assign storage and bootstrap/cache to the PHP user. With a bind mount in development, align the container UID with yours instead (that is what Sail does with WWWUSER).

    dockerfile
    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 artisan with sudo on a server: use sudo -u www-data or a deploy user that belongs to the www-data group.
  • Add the storage and bootstrap/cache permission 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

All PHP & Laravel errors →