Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

soury's avatar
Level 1

How to fix `laravel recent daily log file has been deleted`

I use laravel 5.4 and daily logs for log error. But sometimes the current log is deleted and laravel generates this error:The stream or file "/storage/logs/laravel-2019-09-06.log" could not be opened: failed to open stream: Permission denied but the file has been already created.

I create manualy the log file and put this permission chmod 775 -R to storage directory but it gets lost anyway.

0 likes
7 replies
Snapey's avatar

The problem occurs when the webserver does not create the log file.

Do you have cron jobs? This is usually the issue. If, say, the cronjob runs under your account or root, and runs the scheduler just after midnight and creates a log file then the log file will be owned by root and not writable by the web server when it comes to use it.

If no scheduler runs and the webserver finds the file is missing then it is able to create the file no problem.

Later versions of Laravel allow you to specify what permissions are used when the log file is created. This allows your account and www-data to be in the same group and you can make the log group writable.

Other options I have seen are to set the cron up in www-data name, or to tell the logger to use a different log file for cron.

1 like
soury's avatar
Level 1

yes I actually have cron then what you might be right, so if I set the cron to run with the same user the problem should be solved. I try and let you know thanks.

soury's avatar
Level 1

Today I've made my crontab that it's executed by user called www-data that is the same user that use my application. As you said, that's could resolve my problem...but in my opinion it doesn't work because the file log doesn't exist in my server. So my file hasn' been created or someone (something) has cancelleted its..in my opinion the problem is the second one because i've created a lot of time this file, but when I come back to check if it exists , it doesn't exist :( Anyway for this time, I use this setting and I'll see if the problem wil come back again and again.

itsfg's avatar

We had this problem too in some applications. This was our solution :

Our webserver user is called "www", member of a group called "laravel". Composer user is also member of this "laravel" group :

## create user group
sudo groupadd laravel

## add composer user to group
sudo gpasswd -a yourlogin laravel

## add web server to group
sudo gpasswd -a www laravel

First, reset/set all permissions in your project :

## jump to laravel path
cd /path/to/your/laravel-application

## optional: if you've been playing around with permissions
## consider resetting all files and directories to the default
sudo find ./ -type d -exec chmod 755 {} \;
sudo find ./ -type f -exec chmod 644 {} \;

## give users part of the laravel group the standard RW and RWX
## permissions for the existing files and folders respectively
sudo chown -R :laravel ./storage
sudo chown -R :laravel ./bootstrap/cache
sudo find ./storage -type d -exec chmod 775 {} \;
sudo find ./bootstrap/cache -type d -exec chmod 775 {} \;
sudo find ./storage -type f -exec chmod 664 {} \;
sudo find ./bootstrap/cache -type f -exec chmod 664 {} \;

And then, this is how we declare that every new file created should have the same permissions as the parent directory :

## give the newly created files/directories the group of the parent directory 
## e.g. the laravel group
sudo find ./bootstrap/cache -type d -exec chmod g+s {} \;
sudo find ./storage -type d -exec chmod g+s {} \;

## let newly created files/directories inherit the default owner 
## permissions up to maximum permission of rwx e.g. new files get 664, 
## folders get 775
sudo setfacl -R -d -m g::rwx ./storage
sudo setfacl -R -d -m g::rwx ./bootstrap/cache

## Reboot so group file permissions refresh (required on Debian and Centos)
sudo shutdown now -r

Now, even if the root user creates the log file, it is readable/writable by the webserver user.

We now always execute this script file after a fresh laravel install.

Maybe it helps ?

1 like
soury's avatar
Level 1

Hello @itsfg,

thank you for your response.

We tried this yesterday both on our test server and our production server and it seems that it worked well; no more log errors for now.

The only detail that went wrong is that only on our production server (test worked fine) the command sudo setfacl -R -d -m g::rwx ./bootstrap/cache returned an "Operation not supported" error.

However this doesn't seem to void the functionality of our program.

Thank you for your help.

soury's avatar
Level 1

@itsfg thanks for your support. I have already executed the instructions indicated in this link but they did not solved the problem. However our system is working correctly and we have not yet encountered the log problem therefore we can consider the problem solved

@itsfg @snapey Thanks for your help :)

Please or to participate in this conversation.