问题
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