laravel artisan command cron job is not working on ubuntu server - php

I am new to Ubuntu server and i install cron job and then make new cron job and no idea why its not working. My application is in Laravel so i have to run artisan command through cron job! When i am in project through root cmd artisan-command run properly but in cron did not run it.
here is my cron job listed
I check the if its running or not like this:
# sudo grep -i cron /var/log/syslog|tail -3
This is the output:
Jan 21 09:30:01 liedergut CRON[5222]:(root) CMD (/path/to/php/bin/php /var/www/html/artisan shows:fetchrss >> /dev/null 2>&1)
Jan 21 09:30:01 liedergut CRON[5223]: (root) CMD (php /var/www/html/artisan shows:fetchrss >> /dev/null 2>&1)

Most certainly /var/www/html/php and /path/to/php/bin/php do not exist. You can find out where the php executable is by using whereis php (as you stated in your comment, it is /usr/bin/php). So to make your artisan command run every minute your cron line should be
* * * * * /usr/bin/php /var/www/html/artisan shows:fetchrss >> /dev/null 2>&1
I would suggest though to run Laravel's scheduler every minute:
* * * * * /usr/bin/php /var/www/html/artisan schedule:run >> /dev/null 2>&1
and schedule your artisan command inside of Laravel, as written on Laravel's task scheduling documentation. This way you can manage your scheduled jobs or re-schedule them without having to edit/touch your crontab.

This command works for me
* * * * * cd /var/www/html/projectname && php artisan schedule:run >> /dev/null 2>&1

Related

Laravel schedule:run is not working when added into the cron job

I have made a command and scheduled it for every 30 minutes. When I run php artisan schedule:run it works perfectly fine and returns with the expected results, but when I configured it on my live server my cron job do run but instead of retuning the success message it returns with list of all available command in my laravel project. Here is what I am doing.
Command Kernel:
$schedule->command('update:callLogs')
->everyMinute();
Cron Entry:
/usr/bin/php /home/ddsas9rm2f1g/public_html/clowdlink.com/crm/artisan schedule:run
And this is the response I am getting
Laravel Framework 5.8.38
Usage:
command [options] [arguments]
Options:
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
--env[=ENV] The environment the command should run under
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Available commands:
(List of all availabe commands)
Any help will be much appreciated.
EDIT
Now my command looks like this
* * * * * cd /home/ddsas9rm2f1g/public_html/clowdlink.com/crm && php artisan update:callLogs
but getting the same response whereas when I copy the same command and using putty ran the same command and it works perfectly fine. Now it's been a week now and I'm still stuck at this cron thing.
I fixed this by specifying the path to PHP instead of using just php.
From this: cd /home/foobar && php artisan schedule:run
To this: cd /home/foobar && /usr/local/bin/php artisan schedule:run
This stopped me from getting a list of available artisan commands and gave me the right output.
I can see it looks like you've already tried that, but I think others will run into this too. I'd imagine your issue is something to do with the PHP version you're using not being able to properly run PHP scripts. Maybe an opcache thing with CLI?
I faced big challenge as well when I was deploying one my applications, and finally managed to tackle it with:
cd /path-to-project && /opt/cpanel/ea-php71/root/opt/cpanel/ea-php74/root/usr/bin/php-cgi artisan schedule:run
I use Laravel 5.7 for my application
You could try the following code:
* * * * * php /home/ddsas9rm2f1g/public_html/clowdlink.com/crm/artisan schedule:run 1>> /dev/null 2>&1
>> /dev/null 2>&1: we will discard all output of a command.
Can you try the below in cron and share the output of crontab.out
* * * * * cd /home/ddsas9rm2f1g/public_html/clowdlink.com/crm/ && php artisan schedule:run >> crontab.out 2>&1
*/30 * * * * php /home/ddsas9rm2f1g/public_html/clowdlink.com/crm/artisan schedule:run 1>> /dev/null 2>&1
OR
*/30 * * * * /usr/bin/php /home/ddsas9rm2f1g/public_html/clowdlink.com/crm/artisan schedule:run 1>> /dev/null 2>&1
OR
*/30 * * * * cd /home/ddsas9rm2f1g/public_html/clowdlink.com/crm && php artisan schedule:run >> /dev/null 2>&1
Also read full post: https://devnote.in/how-to-set-auto-database-backup-with-cron-scheduler-in-laravel/

cron not running on ubuntu 16.04 laravel

I have php 7.2 installed in ubuntu 16.04. (/usr/bin/php7.2 is there not /usr/bin/php)
I have set following commnad to rub cron:
* * * * * /usr/bin/php /var/www/html/artisan schedule:run >> /dev/null
2>&1
or should I write below command
* * * * * cd /var/www/html && php artisan schedule:run >> /dev/null 2>&1
yestreday, I kill cron process to stop running cron and started again with following command
sudo service cron restart
but somehow, cron is not running automatically.
Any suggestions would be great.

Laravel cronjob schedule command not firing on production

I have 7 different schedule commands on kernel.php and one of those is not firing when running the schedule.
kernel.php
....
$schedule->command('my:command')->hourlyAt(15); // this wont run
...
Running php artisan my:command manually on command line works fine.
Also when running the scheduler on our dev server, all commands works fine. The problem is only on production server.
There are no errors on log files.
Any ideas what might be wrong?
I'm using Laravel 5.6
UPDATED:
The problem was wrong artisan path on laravel forge scheduler
Have you add following cron entry as per your project folder path ?
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
please check with following commands
crontab -l
If not ?
open crontab by
crontab -e
add * * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1 entry at the end of file
save file and run following commands
sudo service cron restart
again check with crontab -l
this command will return already set cronjob
i hope it helps :)

laravel 5.5 schedule:run cron job not working in cpanel

I'm have a laravel5.5 project up on shared hosting and trying to run cron job to execute the command "schedule:run" but it just won't execute I think I'm writing the command wrong:
/usr/local/bin/php home/schoolco/prototype/artisan schedule:run >> /dev/null 2>&1
where prototype in the name of my laravel project.
the command works in this directory using ssh.
please if you have any observation or thought share it.
Try like this
/usr/local/bin/php /home/schoolco/prototype/artisan schedule:run > /dev/null 2>&1
And check are you calling right php executable in your terminal with:
$ which php
Maybe it is not /usr/local/bin/php , maybe /usr/bin/php
If your Project is in Root Directory
cd /home/cpanel/public_html && /usr/local/bin/ea-php72 artisan schedule:run >> /dev/null 2>&1
If your Project in a folder within Public_Html then use below
cd /home/cpanel/public_html/folder_name && /usr/local/bin/ea-php72 artisan schedule:run >> /dev/null 2>&1
Hope it will work for you. Thanks
I solved the issue by specifying the php version in the command line:
* * * * * /usr/local/bin/ea-php71 /home/nemanu/root1/artisan schedule:run >> /dev/null 2>&1

Laravel artisan cron task not working on ubuntu

I have been pulling my hair out for the past 5 hours over what I thought would be a simple task, enabling the cron feature for Laravel. I am running Laravel 5.1 on an Amazon EC2 Ubuntu LAPP stack server.
I have added the cron task to the cron jobs list using the command
sudo crontab -e
Then I have added the command listed in the laravel documentation
* * * * * php /home/bitnami/htdocs/project/app/artisan schedule:run >> /dev/null 2>&1
I have made sure that cron is running and I can see that the task is running if I run
sudo grep -i cron /var/log/syslog|tail -3
Which returns
Mar 4 15:36:01 ip-172-31-7-174 CRON[15120]: (root) CMD (php /home/bitnami/htdocs/project/app/artisan schedule:run >> /dev/null 2>&1)
Mar 4 15:37:01 ip-172-31-7-174 CRON[15123]: (root) CMD (php /home/bitnami/htdocs/project/app/artisan schedule:run >> /dev/null 2>&1)
Mar 4 15:38:01 ip-172-31-7-174 CRON[15125]: (root) CMD (php /home/bitnami/htdocs/project/app/artisan schedule:run >> /dev/null 2>&1)
I have tested that the path has not got any typos in it by running the command from the command line and it works properly
php /home/bitnami/htdocs/project/app/artisan schedule:run
Also I have added this cron task just to confirm that cron is actualy running
* * * * * echo "Cron" > /home/bitnami/htdocs/project/app/artisan/file.txt
I have also made sure the file is executable by doing the following but this has not fixed the issue either
chmod 755 artisan
chmod 777 artisan (I am aware this is dangerous)
chmod +x artisan (Suggested on fourms)
Does anyone have any suggestions where I'm going wrong here.
I've experienced this and found a solution. It's because of unknown reason in bitnami, so that php command not recognized by cron. I used this command to make it working :
* * * * * /path/to/php/bin/php /home/bitnami/htdocs/project/app/artisan schedule:run 1>> /dev/null 2>&1

Categories