0

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.

moonwalker
  • 1,157
  • 1
  • 18
  • 34
  • 1
    You can try giving permissions to the user "www-data" or the user that you are using to the storage directory sudo chown -R www-data:www-data /path/to/your/project/storage https://stackoverflow.com/questions/30639174/file-permissions-for-laravel-5-and-others – Raúl Monge Nov 21 '18 at 17:43
  • the folder `tmp` is owned by www-data and it has write permissions to that folder. The upper folders such as `storage` on the other hand is owned by me (not root) and www-data group and we both have write permissions. Do I need execute permission for www-data on `tmp` directory to delete files? – moonwalker Nov 21 '18 at 17:50
  • It doesn't give you some error when you execute the "php artisan schedule:run"? – Raúl Monge Nov 21 '18 at 17:54
  • Yes no errors there. Just says the command is due and executes it as everything is fine. And the log file `taskoutput.log` is empty. – moonwalker Nov 21 '18 at 17:55

0 Answers0