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

amirkamizi's avatar

Permission Denied for daily logs in laravel

recently I changed the logs from single to daily.

'mlog' => [
            'driver' => 'daily',
            'path' => storage_path('logs/mlog.log'),
            'level' => 'debug',
        ],

and noticed that for logs for the new day I get this error

The stream or file "/path_to_laravel_project/storage/logs/mlog-2021-05-29.log" could not be opened in append mode: failed to open stream: Permission denied"
  #code: 0
  #file: "/path_to_laravel_project/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php"
  #line: 111

log files are by default 644 and when I change them to 777 it's fixed.

but why this happens? and how can I make the default mode for new logs to be 777 or 775 so I wouldn't get this error everyday?

0 likes
5 replies
tisuchi's avatar

@amirkamizi You can pass permission also in mlog.

For Example-

'mlog' => [
    'driver' => 'daily',
    'path' => storage_path('logs/mlog.log'),
    'level' => 'debug',
    'permission' => 0777,
],
1 like
Snapey's avatar

its never a good idea to blast the permissions

the cause is probably that you run cron under a different account to your webserver. Check the owner of the log in the directory listing

The easiest solution, and what I do, is edit the crontab as the www-data user

crontab -u www-data -e

but remember to stop the previous one

amirkamizi's avatar

in the cron, I only added the laravel schedule. You mean that is causing this?

Snapey's avatar

if you run crontab -e then you are running all the cronjobs in your account.

If you have a job that runs just after midnight, each daily log will be created by you.

The Laravel application can then not create or update the daily log.

If you remove that entry and instead create it with the -u option and specify the name of the web server then the log file will be created by the webserver when cron jobs run

1 like

Please or to participate in this conversation.