I am trying to run an artisan command from a cron task but I keep getting errors.
In Plesk I have created this task:
php /var/www/vhosts/domainxxx.co.uk/httpdocs/artisan schedule:run
I’m trying to run a queue
However I get an error
Could not open input file: php /var/www/vhosts/domainxxx.co.uk/httpdocs/artisan schedule:run
if I run the command php artisan schedule:run
from the httpdocs directory it works.
I’ve tried loads of combinations of the path and full path to php but nothing seems to work.
What am I doing wrong?
Fiddling about I created a test script in the httpdocs called crontest.php
which just echoed out a status. I’m able to get this running with cron using this command:
/usr/bin/php /var/www/vhosts/domainxxx.co.uk/httpdocs/crontest.php
The log I get shows as the domain user rather than the root user – don’t know if this makes a difference? I can see the test output in the notification I receive.
Switching this to:
/usr/bin/php /var/www/vhosts/domainxxx.co.uk/httpdocs/artisan schedule:run 1
I get the error:
/usr/bin/php: No such file or directory
Confused – does this error relate to php or artisan (assume artisan as it works for the tst script). Can anyone help please. Artisan is definately there 🙁
2
Answers
After plenty of searching and trial and error the issue related to the "system user" SSH settings for the domain.
I managed to created the task successfully in the root users cron ("system wide"). This worked so after plenty of digging had to set SSH access for the user the cron jobs were being run under - assumed already had access
Once set the files and folders became accessible and the cron jobs now run successfully - phew!
Thanks for your help ROn Brouwers
I had the exact same issue. Using a simple cron that pointed to a simple php script worked. So what I had to do, is first CD to the correct directory. Switching out my own path with yours, the full cronjob would look like so:
It wasn’t an error with laravel or artisan for me, but really just with the cronjob itself.