DEV Community

dkelxldk
dkelxldk

Posted on

Handling laravel logs user/owner suddenly change

Have you encounter your laravel logs user/owner suddenly changes to root? or any other user?

here's some probabilities that what make it happen

First

you have some queues that run as another user. Let's say your application owner/groups is nginx:nginx. But you used supervisor to run your queues and your setting is like this

[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/html/laravel-app/artisan queue:work sqs --sleep=3 --tries=3 --max-time=3600
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=root
numprocs=8
redirect_stderr=true
stdout_logfile=/var/www/html/laravel-app/logs/worker.log
stopwaitsecs=3600
Enter fullscreen mode Exit fullscreen mode

when an error happened, since the queues is running as root, it will try to write to your logs as the root. that's why your logs owner/groups now changes to root.

To fix that, just change the supervisor config of user from root to your application owner/group

user=nginx
Enter fullscreen mode Exit fullscreen mode

Second

you have a scheduler, and you setup your scheduler as a root. When you try to setup is like this

$ sudo crontab -e
------you're configuring you're scheduler here------
Enter fullscreen mode Exit fullscreen mode

so now you scheduler will run as root. the same thing when error happened, it will try to write to your logs as the root. that's why your logs owner/groups now changes to root.

To fix that, just setup your scheduler as the owner/group of your application.

$ sudo --user=nginx crontab -e
------you're configuring you're scheduler here------
Enter fullscreen mode Exit fullscreen mode

Top comments (0)