Laravel task scheduler permission problem with cleanDirectory command

ⅰ亾dé卋堺 提交于 2020-12-15 04:28:29

问题


I've set up a console command with a handle() function like this:

public function handle()
{
  $fileSystem = new Filesystem;
  $fileSystem->cleanDirectory('storage/app/public/tmp');
}

And in the console kernel I set up the command:

    $schedule->command('cleanupfiles:tmp')
              ->everyMinute()
              ->sendOutputTo(storage_path('logs/taskoutput.log'));

The superuser's crontab has the following entry:

    * * * * * php /var/www/website/artisan schedule:run >> /dev/null 2>&1

I can see the task scheduler getting executed every minute by looking at the /var/log/syslog, so cron does it's job, but the folder contents are not cleaned. When I run the task directly on the terminal by: php artisan schedule:run I have the same effect; no files are deleted. Finally when I run the schedule with sudo php artisan schedule:run I see it works, files get deleted and output is written to taskoutput.log.

How can I solve this so the task runs with necessary permissions? Or is there anything else I miss here? Thanks.

来源:https://stackoverflow.com/questions/53415222/laravel-task-scheduler-permission-problem-with-cleandirectory-command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!