Search code examples
phplaravelcroncpanel

Cron in Laravel and Cpanel


Laravel cron issue on Cpanel

Background info

  • Laravel 10
  • cpanel shared hosting
  • crons set up and tested locally

I have a tested set of crons that run jobs/queues in my local environment. When I attempted to upload them to the cpanel server the crons seemed to not be working. I emailed the output to myself to debug it.

Issue

When I run a cron on my cpanel hosting, the command seems to lose options.

I am using the cpanel cron editor (I only have basic command line access, and no crontab).

If I run:

php /home/accountname/www/artisan schedule:run

I get the an email that contains the artisan "with no options" help content... ie:

Usage: command [options] [arguments]

Options: -h, --help Display help for the given command. When no command is given display help for the list command -q, --quiet Do not output any message -V, --version Display this application version --ansi|--no-ansi Force (or disable --no-ansi) ANSI output ...

The commands work exactly as expected when run directly from command line.

[Edit]

I have been able to check crontab -l and the crons are normally added.

MAILTO="[my email]"
SHELL="/bin/bash"
* * * * * php /home/accountname/www/artisan schedule:run
* * * * * php /home/accountname/www/artisan queue:work --stop-when-empty

^ they seem to be correctly added.

Question

How do i get the cron editor to read the options from this command?


Solution

  • For some reason, this seems to come from not using the correct php version.

    It was fixed by changing to the local version of php:

    • /usr/local/bin/php