i am hosting my laravel application with namecheap, i have also followed all the instructions here https://www.namecheap.com/support/knowledgebase/article.aspx/9453/29/how-to-run-scripts-via-cron-jobs . however after setting my cron job in the cron job tab of cpanel, i get notifications in my email but the artisan command does'nt seem to be executed as my database remains the same. i tried to echo out a value in the artisan command's handle method for testing purposes but then nothing gets output and i still get notifications in my email like so => 'Running scheduled command: '/opt/alt/php70/usr/bin/php' 'artisan' deactivate:ads > '/home/agrodqkc/applications/agroexpresslink/app/console/log.txt' 2>&1 &'
This is my cron command for every minute => /usr/local/bin/php /home/agrodqkc/applications/agroexpresslink/artisan schedule:run
my kernel.php file :
<?php
namespace mazee\Console;
use Illuminate\Console\Command;
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\Inspire::class,
Commands\maz::class,
Commands\deactivateads::class,
];
/**
* Define the application's command schedule.
*
* #param \Illuminate\Console\Scheduling\Schedule $schedule
* #return void
*/
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')
// ->hourly();
//$schedule->command('maz:do')->everyMinute()->sendOutputTo(base_path().'/app/console/log.txt')->emailOutputTo('ewomaukah#yahoo.com');;
$schedule->command('deactivate:ads')->everyMinute()->sendOutputTo( base_path().'/app/console/log.txt');
}
}
Can you show the cron command that you are running because I think the cron job is not set properly
if you access your server using ssh and enter crontab -e
OR
You might have a dedicated tool to set cronjobs in cPanel
The CRON job should be set as following:
* * * * * /opt/alt/php70/usr/bin/php /home/agrodqkc/applications/agroexpresslink/artisan schedule:run >> /dev/null 2>&1
The above command will run every minute and will search for scheduled tasks.
Finally i got mine to work after days of frustration i discovered that because laravel app requires you to put public files of your app in public_html folder and main files on your separate folder outside of public_html so to register a cron job use this
/usr/local/bin/php /home/username/separatefolder/artisan schedule:run >> /dev/null 2>&1
Related
I am using Task Scheduling from Laravel, on local env. and till now I test it with php artisan word:weeklyUpdate , but I want to check if the Cron Job run automatically on a specific date, like in my code.
protected function schedule(Schedule $schedule)
{
$scheduler = new LkpSchedulerUpdateDate;
$scheduler = $scheduler->first()->toArray();
$schedule->command('word:weeklyUpdate')->weeklyOn($scheduler->date, $scheduler->time);
//ex: weeklyOn(3, 05:49:00)
}
Create a schedule that runs just some minuts after the current time (let's say 5 minuts from now), wait, then check the results.
Edit:
It's because when you run php artisan word:weeklyUpdate` you execute the command directly.
The scheduled task your wrote is equivalent to execute php artisan word:weeklyUpdate in console every week.
Also, in your locale did you activated the cronJob scheduler?
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
Laravel scheduler doesn't work in Dreamhost VPS.
Dreamhost has a limitation of not allowing every minute calls so I am doing it in a 10 minute call instead. However, the scheduler doesn't fire in any case.
I have tried the following cron commands:
php ~/site.com/artisan schedule:run >> /dev/null 2>&1
and
cd / site.com && php artisan schedule:run >> /dev/null 2>&1
But both do not work.
Here's what I have inside my kernel.php
protected $commands = [
'App\Console\Commands\DailyStatus',
];
/**
* Define the application's command schedule.
*
* #param \Illuminate\Console\Scheduling\Schedule $schedule
* #return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('status:daily')
->timezone('Asia/Manila')
->dailyAt('6:50');
$schedule->command('status:daily')
->timezone('Asia/Manila')
->daily()
->between('12:00','12:30')
->appendOutputTo(public_path().'status_daily_output.log')
->withoutOverlapping(60);
$schedule->command('status:daily')
->timezone('Asia/Manila')
->dailyAt('12:15')
->appendOutputTo(public_path().'status_daily_at_output.log')
->withoutOverlapping(60);
}
The logs are also not being generated. I have put some echo commands and its not firing.
How can I test if my scheduler is properly configured?
Can someone help me fix my current setting?
Thank you.
So I managed to get this to work after a number of testing.
Make sure that your account can execute the command
crontab -e
If you can't, contact Dreamhost support to have the permissions fixed.
For your cron command, you need to specify the exact location of your php
cd ~/site.com && /usr/local/php72/bin/php artisan schedule:run >> /dev/null 2>&1
Since everyminute is not allowed by Dreamhost, I suggest executing it at every 10 minutes instead.
I hope this helps!
In my laravel application under routes/console.php have one command. I want to run this command every minute which is given below:
Artisan::command('inspire', function () {
$this->comment(Inspiring::quote());
})->describe('Display an inspiring quote');
In digital ocean crontab i registered below command but not working.
* * * * * cd /var/www/html/laravel_projects/user_profile/ && php artisan schedule:run 1>> /dev/null 2>&1
N.B: In digitalocean cron status showing it's active and if i run this command under project directory manually & its' working.
You need to define a schedule to tell Laravel which commands you want to run.
Your task schedule is defined in the app/Console/Kernel.php file's schedule method.
protected function schedule(Schedule $schedule)
{
$schedule->command('inspire')->daily(); // or some other time
}
https://laravel.com/docs/5.8/scheduling#defining-schedules
Add task schedule inside App\Console\Kernel.php
protected function schedule(Schedule $schedule)
{
$schedule->command('reminders:send')->everyMinute();
}
I hope it helps.
sudo service cron restart
execute this command to restart cronjob service
I've set up a console command with a handle() function like this:
public function handle()
{
$fileSystem = new Filesystem;
$fileSystem->cleanDirectory('storage/app/public/tmp');
}
And in the console kernel I set up the command:
$schedule->command('cleanupfiles:tmp')
->everyMinute()
->sendOutputTo(storage_path('logs/taskoutput.log'));
The superuser's crontab has the following entry:
* * * * * php /var/www/website/artisan schedule:run >> /dev/null 2>&1
I can see the task scheduler getting executed every minute by looking at the /var/log/syslog, so cron does it's job, but the folder contents are not cleaned. When I run the task directly on the terminal by: php artisan schedule:run I have the same effect; no files are deleted. Finally when I run the schedule with sudo php artisan schedule:run I see it works, files get deleted and output is written to taskoutput.log.
How can I solve this so the task runs with necessary permissions? Or is there anything else I miss here? Thanks.
With older versions of Laravel I only had to write a command in Forges controlpanel eg php /home/forge/default/artisan scheduled:run then set the interval and hit schedule button.
Now in Laravel 5.5 I can se that I can add jobs in the kernel.php file eg:
protected function schedule(Schedule $schedule)
{
$schedule->command('SomeJob:delete')
->daily();
}
Does this mean I no longer have to setup cron jobs in laravel Forge?
You still need one cron entry to start the scheduler:
* * * * * php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1