Ubuntu setup cronjob every 5 minuetes not working - php

I am using Ubuntu 16.04 LTS, and I want to set up cron job for my laravel services. this is how I set up
5 * * * * php /var/www/myapp/artisan schedule:run 1>> /dev/null 2>&1
and in my laravel app kernel.php
protected function schedule(Schedule $schedule)
{
$schedule->command('email:send')
->dailyAt('03:30');
$schedule->command('queue:work')->everyFiveMinutes();
}
it did not trigger, I don't know why it did not trigger the command
Thank you in advance.

You should use this:
*/5 * * * * php /var/www/myapp/artisan schedule:run 1>> /dev/null 2>&1

Related

Laravel Cron Job not working on AWS lightsail LAMP

I am using Laravel 7 and AWS lightsail LAMP server for my application.
When I am running this
php artisan schedule:run
command manually it's working properly. But, when I am creating a cron job for this it's not working.
Here is my cron code as laravel documention:
* * * * * cd /opt/bitnami/apache/htdocs && php artisan schedule:run >> /dev/null 2>&1
Here is my app/Console/Karnel.php
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* #var array
*/
protected $commands = [
Commands\DeactiveCoupon::class
];
/**
* Define the application's command schedule.
*
* #param \Illuminate\Console\Scheduling\Schedule $schedule
* #return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('coupon:deactive')->everyMinute();
$schedule->command('queue:restart')->everyMinute();
$schedule->command('queue:work')->everyMinute();
}
/**
* Register the commands for the application.
*
* #return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}
But, if I add this cron:
* * * * * cd /opt/bitnami/apache/htdocs && touch mytestfile.txt >> /dev/null 2>&1
It's creating a new file named mytestfile.txt
But, this Laravel command not working in cron!
* * * * * cd /opt/bitnami/apache/htdocs && php artisan schedule:run >> /dev/null 2>&1
How can I solve this?
Yes on live server you can register it through cron job
then you can register you command in cron job. you can ask you server provider for this command and then register like this
command look like this
/usr/local/bin/php /home/escuelar/your folder name/artisan schedule:run 1>> /dev/null 2>&1
After I run
which php
I got
/opt/bitnami/php/bin/php
and my cron code is:
* * * * * cd /opt/bitnami/apache/htdocs && /opt/bitnami/php/bin/php artisan schedule:run >> /dev/null 2>&1
It's working for me
Thanks #apokryfos bro

Laravel Kernel Task Schedule not working properly

I'm trying to use Laravel Task Schedule. So I create crontab -e which is like blow.
* * * * * cd /var/www/html/laravel && php artisan schedule:run >> /dev/null 2>&1
After this I bind my commands to Laravel's App/Kernel which is like below:
protected $commands = [
//
Commands\mitsui::class,
Commands\sumitomo::class,
Commands\nomura::class,
];
And schedule:
protected function schedule(Schedule $schedule)
{
$schedule->command('bot:mitsui')->everyMinute();
$schedule->command('bot:sumitomo')->everyMinute();
$schedule->command('bot:nomura')->everyMinute();
}
Actually it's weekly but I'm trying to checking is it working or not. That's why make it everyMinute But actually it's not working. commands are not running. Do I missing something here?
change this line
* * * * * cd /var/www/html/laravel && php artisan schedule:run >> /dev/null 2>&1
to
* * * * * php /var/www/html/laravel/artisan schedule:run >> /dev/null 2>&1

Digitalocean cron and Laravel

I have a hard time running cron job on Digitalocean. I noticed there are two different cron files, I get to one by getting to /etc/crontab and other one by entering the command crontab -e.
To make it more confusing, both of those have somewhat different "layout". First one:
* * * * * root php /var/www/Laravel artisan schedule:run >> /home/laravel.log
and second one:
* * * * * php /var/www/Laravel artisan schedule:run >> laravel.log
Here is Laravel scheduler part:
protected $commands = [
'App\Console\Commands\SyncAPIs',
];
/**
* Define the application's command schedule.
*
* #param \Illuminate\Console\Scheduling\Schedule $schedule
* #return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('media:sync')->everyThirtyMinutes();
// sync for yesterday to eliminate discrepancies
$schedule->command('media:sync ' . Carbon::yesterday())->dailyAt(6);
}
The thing is that the laravel.log does get created, but I see nothing in it, and I don't know if my commands actually get ran. Does that mean that cron IS actually running? How can I debug the issue as I don't see in the database that cron filled it. When I go to the folder /var/www/Laravel and execute the commands which are supposed to be called in scheduler, dataabse fills correctly.
cd ~
crontab -u root -e
* * * * * php /var/www/laravelprojectname/artisan schedule:run 1>> /dev/null 2>&1
service cron restart
grep -i cron /var/log/syslog|tail -3
I think this should help
May be you need to change this line :
* * * * * php /var/www/Laravel artisan schedule:run >> laravel.log
to :
* * * * * /usr/bin/php /var/www/Laravel artisan schedule:run >> laravel.log
I found an answer being actually:
* * * * * php /var/www/Laravel/artisan schedule:run >> laravel.log
php works globally, but artisan needs to be shown the path which is in my Laravel main folder

Laravel + Crontab not working

I am trying to set up scheduler in Laravel.
Here is my crontab which I debugged and works fine - atleast with my cron job
* * * * * /bin/echo "foobar" >> /my_path/example.txt
I don't know if this one works:
* * * * * php /var/www/myproject/artisan schedule:run 1>> /dev/null 2>&1
Here is my schedule function in Kernel:
protected function schedule(Schedule $schedule)
{
$schedule->command('inspire')
->everyMinute();
}
When I am in my project and try php artisan inspire it actually works, so I expected it to fire every minute, but it won't do anything. Nothing happens.
Any ideas?
This part just puts the output into oblivion so you'll never see it:
>> /dev/null 2>&1
Why not try:
* * * * * php /var/www/myproject/artisan schedule:run >> /my_path/example.txt
And check to see if the cron is run in /my_path/example.txt
The default inspire command essentially just echo's a quote so the only way to see it in a cron is to output it to a file on the server.
You can do this using something similar to this:
$schedule->command('inspire')->everyMinute()->appendOutputTo($filePath);
Further details: https://laravel.com/docs/5.4/scheduling#task-output
you should try something
like * * * * * cd /Path/TO/YOUR_PROJECT/ && php artisan schedule:run >> /dev/null 2>&1
Am also using laravel 4.2, Here is my Cron command which currently working good.
0 0 * * * /usr/local/bin/php /*****/******/public_html/artisan command:firemyevent
Hope It will help you.
in my case, I had to explicity a php version compatible with laravel, in my cron job:
cd /path/to/my/project && /usr/local/bin/ea-php71 artisan schedule:run > /dev/null 2>&1
I made it run in mac through:
* * * * * cd /Applications/XAMPP/xamppfiles/htdocs/rcraze && /usr/local/bin/php artisan schedule:run >> /dev/null 2>&1
You have to put full path of PHP (you can get it through whereis php command in MAC terminal) and pull path of your project.

Run automatically schedule in xampp with laravel

I have defined a command and make it can run every minutes in Kernel with schedule. But when i use artisan command to run, it only run once time.So, i want to make it run auto every minutes in Xampp in window 10. But how can i add :
* * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1 to my server
Can i have run scheduler automatic?
In :
public function handle()
{
$banMember = MemberAccount::where('isBan',1)->get();
foreach($banMember as $ban)
{
$ban->isBan = 0;
$ban->save();
}
}
Here are some hints for you to do the task scheduling
https://www.drupal.org/docs/7/setting-up-cron-for-drupal/configuring-cron-jobs-with-windows
http://www.z-cron.com/
* * * * * means that it has to be running every minute.

Categories