Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

noblemfd's avatar

Cron job not updating automatically on live server

I have this cron job on my Digital Ocean Ubuntu live server:

namespace App\Console\Commands;App/Console/Command

class UpdateCreateEmployeeDepartment extends Command
{

    protected $signature = 'updatecreateemployeedepartments';

    protected $description = 'Update or Create Employee Department';

    public function __construct()
    {
        parent::__construct();
    }

    public function handle()
    {
        // Select all employees that haven't been updated
        $employees = HrEmployee::where('is_nav_updated', 0)->where('company_id', 1)->get();        


        // For each of the employees selected above
        foreach ($employees as $employee) {
            $department = HrDepartment::where('dept_code', $employee->nav_dept_id)->where('company_id', 1)->first();

            // If a department was found, update the employee
            if ($department) {
                $employee->department_id = $department->id;
                $employee->is_nav_updated = 1;
                $employee->save();
            }            

        }        

    } 

}


namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{

    protected $commands = [

        'App\Console\Commands\UpdateCreateEmployeeDepartment',
    ];

    protected function schedule(Schedule $schedule)
    {
         $schedule->command('updatecreateemployeedepartments')
                  ->dailyAt('01:00');           
    }

    protected function commands()
    {
        $this->load(__DIR__.'/Commands');

        require base_path('routes/console.php');
    }
}

I observed that it's not running automatically as scheduled until when I manually run:

php artisan updatecreateemployeedepartments

How do I resolve this?

Thanks

0 likes
5 replies
Snapey's avatar

is your scheduler actually working every minute?

noblemfd's avatar

@snapey - I schedule it to work daily by 1:00 am but its not working until when I run php artisan

Snapey's avatar

You have to run the scheduler (php artisan Schedule:run) every minute. When it gets to 01:00 your job will run.

noblemfd's avatar

@snapey - Where do I set this

php artisan Schedule:run

Do you mean I need to do something different from this

protected function schedule(Schedule $schedule)
{
     $schedule->command('updatecreateemployeedepartments')
              ->dailyAt('01:00');           
}

as it is in my code?

Please kindly guide

Thanks

ElMarkesDeSade's avatar

Once you set your scheduled tasks in your Laravel kernel file, then in the server you're using to host your application you have to put this in the cron file:

* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1

Basically it will run the 'php artisan schedule:run' command every minute and depending on the execution configuration of your scheduled tasks they will be executed or not.

Please or to participate in this conversation.