Laravel Schedular not working automatically in server (CPanel) - php

I have this in my Kernal.php
$schedule->call(function () {
DB::table('news')->delete();
})->everyMinute();
when i do
php artisan schedule:run
it works fine.
But when i use cpanel and write in cron job
php /home/allnewsnepal/public_html/artisan schedule:run >> /dev/null 2>&1
the code doesnt run automatically.I dont have access to shell of cpanel.

For cron's in cPanel, you can look in this post:
Run a PHP file in a cron job using CPanel
The things that you should pay attention to are:
Global path of your PHP (e.g. /usr/bin/php)
Global path of your Laravel (e.g. /var/www/html/LaravelProjectName)
In order to start a cron job on Linux based systems, you must specify the user for that cron, let's say the user is root, so the cron job would look like this:
root php /home/allnewsnepal/public_html/artisan schedule:run >> /dev/null 2>&1
Of course with * prefixes depending on your cron schedule

Thanx for the help .
I got my problem solved by doing
php-cli -q /home/allnewsnepal/public_html/artisan schedule:run

Related

Linux scheduled task not working in Laravel

The below cronjob is not working, although the task itself is working when I manually run it using php artisan q:calc .
I just added the path for php and artisan files as shown below, and pasted the command in the terminal.
Am I missing something ?
* * * * * /usr/bin/php /var/www/html/sharp/artisan schedule:run >> /dev/null 2>&1
That command is a cron entry, not something you run in terminal.
For example, under the specific user you would run (depending on your environment):
$ crontab -e
And paste the above to the crontab file.
You can learn more in the docs:
https://laravel.com/docs/master/scheduling
Or by researching how to add cron entries for your specific operating system.

Crontab isn't running Laravel scheduled jobs

I've set up crontab on my AWS-EC2 instance to hit the Laravel scheduling endpoint every minute via the root account using sudo crontab-e:
* * * * * php ~/htdocs/artisan schedule:run >> /dev/null 2>&1
However, despite to the cron logs showing it is indeed running every minute:
Jan 26 12:02:01 ip-172-31-28-116 CRON[5057]: (root) CMD (php ~/htdocs/artisan schedule:run >> /dev/null 2>&1)
the job itself isn't executing.
Running the command php ~/htdocs/artisan schedule:run >> /dev/null 2>&1 straight up triggers the job and works.
I'm really struggling with what is going wrong here, am I missing something?
So, I failed to heed the cron output "No MTA installed, discarding output" - Upon installing an MTA (postfix, via sudo apt-get install postfix), it turned out that for the cronjob, php wasn't findable.
Changing the command to use the output of which php to:
/opt/bitnami/php/bin/php /home/bitnami/htdocs/artisan schedule:run
is now working.
Thanks for your help!
Use absolute paths when adding cron entries. ~/htdocs/artisan that should be set using the full path to your application root directory.
It works when you manually run the command because your environment is set accordingly. Not the case when adding cron entries using sudo.

Laravel not running Cronjob on Ubuntu NGINX

I have setup the follow Laravel Cronjob command:
protected function schedule(Schedule $schedule)
{
$schedule->command('DataDownloader:downloaddata')->dailyAt('19:34');
}
This saves some data from an API into a mySQL database. The command is listed under php artisan and I am able to run it using php artisan DataDownloader:downloaddata.
I have added the Cron entry to my crontab as per Laravel documentation:
* * * * * php /var/www/html/myprojectname/artisan schedule:run >> /dev/null 2>&1
When I run php artisan schedule:run it tells me 'No scheduled commands are ready to run'. I don't really know if this suggests if my Cronjob does not work at all or it is just broken.
Am I missing something or did I do something wrong that prevents the Cron from running?
My server is running Ubuntu with NGINX.
schedule:run command fires other commands that are ready to run at the time of its execution. So it means that in that exact time you ran it, no command was to be started.
However, you have defined cron that runs schedule:run every minute, thus when 19:34 comes, your command will be executed.

How to run laravel cronjob in local linux system?

I have a cronjob with name changeflag. I can use following terminal command to execute this cronjob in local.
php artisan changeflag
In hosting server, I can easily set the execution of console command with cron job.
Is it possible to run above command periodically in local system in Linux automatically as in server ?
or
We have to execute above command through terminal for every test ?
I am using LAMP.
Any help is appreciated.
if you want to add your project's cron jobs in crontab, just add them in crontab file:
change editor to nano (optional)
setenv EDITOR nano
open crontab file
crontab -e
add this line
* * * * * php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1
replace path-to-your-project with the real path and the cron will be executed automatically.
If this doesn't work, replace php with full php path. To find the whole path just type in command line which php.
For more info read the docs

Run artisan command in Kernel.php

i have installed a Laravel package for dumping my database.
The plugin runs find, but i want to run it every day as a cronjob.
Here is the inserted command in Kernel.php:
$schedule->command('db:backup')->dailyAt('01:50');
Unfortunately it hasn't done anything.
Is it possible to run an artisan command direct in the Kernel.php without a Command class ?
Have you made sure to add the task to your system crontab? Typically located at /etc/crontab
* * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1
From https://laravel.com/docs/5.3/scheduling
PHP has no way of executing itself, so you need to set up a system task to call artisan every second, so laravel can evaluate the cron expressions and run them as needed.

Categories