Sayantan Das
Sayantan Das

Reputation: 1641

Laravel log write permission denied

I am facing permission issue with log writing in my laravel app. We have daily logs so a new log file gets created every day. The project folder ownership is set to www-data. And the logs are normally generated with www-data permission. But sometimes the logs are created with root user and then if somewhere I try to write in log I get permission denied and application crashes.

-rw-r--r-- 1 www-data www-data 77016 Sep 12 05:00 laravel-2017-09-11.log
-rw-r--r-- 1 root     root      1240 Sep 12 10:30 laravel-2017-09-12.log

For example, yesterday's log was created by www-data but today it's under root. So I am getting crashes everytime. If I delete the log or change the permission to 777 then it solves for a while until it pops up again. I cannot replicate the issue and don't know why logs are being created under root user. Any help would be appriciated. Thank you.

Upvotes: 1

Views: 2469

Answers (1)

Pubudu Jayawardana
Pubudu Jayawardana

Reputation: 2365

You can run your cron as www-data user.

Ex: * * * * * www-data php /path/to/artisan schedule:run >> /dev/null 2>&1

Upvotes: 6

Related Questions