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

Sven0188's avatar

Laravel 5.6 Cron Job not Working on Shared Hosting

Good day,

I have a Job that I am scheduling every minute to send some mails. When I run

php artisan schedule:run

via Putty it works. But when setting up via cron job it simple does not trigger my Job.

This is my cron job command:

cd /home/user/laravel_dir && php artisan schedule:run >> /dev/null 2>&1 

Please assist me. I am using HawkHost shared hosting.

0 likes
14 replies
Sven0188's avatar

Also when running that exact script via Terminal (cpanel) it works 100%. But just not via Cron job command.

Sven0188's avatar

In my Laravel log file I found the following error:

[2018-10-01 11:07:02] local.ERROR: Invalid argument supplied for foreach() {"exception":"[object] (ErrorException(code: 0): Invalid argument supplied for foreach() at /home/handbrak/laravel_getlicense.co.za/vendor/symfony/console/Input/ArgvInput.php:259)
[stacktrace]
#0 /home/handbrak/laravel_getlicense.co.za/vendor/symfony/console/Input/ArgvInput.php(259): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'Invalid argumen...', '/home/handbrak/...', 259, Array)
#1 /home/handbrak/laravel_getlicense.co.za/vendor/symfony/console/Application.php(935): Symfony\Component\Console\Input\ArgvInput->getFirstArgument()
#2 /home/handbrak/laravel_getlicense.co.za/vendor/laravel/framework/src/Illuminate/Console/Application.php(80): Symfony\Component\Console\Application->getCommandName(Object(Symfony\Component\Console\Input\ArgvInput))
#3 /home/handbrak/laravel_getlicense.co.za/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(122): Illuminate\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#4 /home/handbrak/laravel_getlicense.co.za/artisan(36): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#5 {main}
"}
Sven0188's avatar

Thanks @pardeepkumar but that is exactly what i did. Except I do not have a custom Artisan command. I am using the existing

php artisan schedule:run

command.

Cronix's avatar
Cronix
Best Answer
Level 67

Have you asked the hosting company? Maybe you need to specify the user the cron job is running under, or provide a full path to php.

1 like
Sven0188's avatar

When googling the error most articles talk about the php variabel "register_argc_argv" which I have now set to ON via my .htaccess file.

Yes I talked to hosting company and they also see the same error message that I am getting in my Laravel log file.

Snapey's avatar

If you don't specify the path to the PHP version you want you may end up with the wrong version. I have known hosts with multiple versions of php installed.

Your cron command should be the full path to php and the full path to your project, eg;

* * * * * /usr/bin/php /var/www/html/myproject/artisan schedule:run >> /dev/null 2>&1

1 like
Sven0188's avatar

Okay thanks got it working. Had to include path the php as in such:

cd path\to\laravel_app && /usr/local/bin/php artisan schedule:run >> /dev/null 2>&1
3 likes
salarpro's avatar

@Sven0188 Thank you, it works for me, I'm using shared hosting (A2 Hosting). the solution for me was /usr/local/bin/php

shahidkarimi's avatar

This still did not work for me Cron: * * * * * php /home/something.com/artisan schedule:run >> /dev/null 2>&1 Laravel: 5.5 PHP: 7.2

Please help

Please or to participate in this conversation.