cron job not running in goDaddy shared host for laravel 5.2 - cron

I am trying to run cron job in my laravel 5.2 application hosted in goDaddy shared host.
I have cPanel access and there I added a cron job, something like this:
* * * * * php /home/path/to/artisan schedule:run 1>> /dev/null 2>&1
But the issue is that the server is not calling schedule action in Kernel.php. The same works fine in my local system.
Can anyone point out the mistake please or suggest some way to accomplish this so that server runs the cron job so as to execute defined commands.

Add path of php binary to cron command.
* * * * * path/php /home/path/to/artisan schedule:run 1>> /dev/null 2>&1
Example : /usr/bin/php

Cpanel Cron job command in laravel godaddy and others are same
/usr/local/bin/php /home/ivlssadmin/public_html/inventoryproject/artisan OpeningStocks:openingstocks >> /dev/null 2>&1
Here what you change follow bellow :
/usr/local/bin/php /home/Your Host User Name /public_html/Sub Domain Name/artisan Command Name:Command Name >> /dev/null 2>&1
if you don't have sub domain you write only public html

Make sure you write the correct command in the schedule action. e.g. $schedule->command('send:followup')
Also check the timezone of the crontab if possible are you using utc timezone in your commands this is the default for most servers.

Related

Crontab on shared hosting, not being started

Alright so I'm having an issue.
I've setup this correctly but something is out of order
I added this to my crontab
* * * * * /home/website/public_html/ && php artisan schedule:run >> /dev/null 2>&1
Now if I start this command from my terminal it will work, but on the crontab log I get this
/bin/sh: /home/website/public_html/ : is a directory
After the frequency of the execution (in your case five stars to run every minute) crontab syntax expects to find the command to run.
I guess you want change the working directory before running php, so you need to add cd to change directory:
cd /home/website/public_html/ && php artisan schedule:run
Anyway, there is plenty of examples and explanations about crontab in internet.

On time laravel scheduler command I want to run in background if fail then run again on Ubuntu

Currently i am using nohup php artisan schedule:run >> /dev/null 2>&1 & but some 3 or 4 days later it kills. I want a permanent solution. I tried to create supervisor but it runs again and again but i am looking only one time run in background. If i Autostart=false its not ruining on background. Some one can help i will be great full to you. I have not vast knowledge on Ubuntu server.
When using the scheduler, you only need to add the following Cron entry to your server. If you do not know how to add Cron entries to your server, consider using a service such as Laravel Forge which can manage the Cron entries for you:
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
This Cron will call the Laravel command scheduler every minute. When the schedule:run command is executed, Laravel will evaluate your scheduled tasks and runs the tasks that are due.
https://laravel.com/docs/7.x/scheduling

how to setup cron job for Lumen Applicaiton in shared hosting (using CPanel)?

I have created one command which will add some record to mysql database.
When I execute command with terminal, command is adding data to database.
Then I have modified Kernel.php, added command in commands array and scheduled task as below.
protected $commands = [
\App\Console\Commands\AddData::class,
];
protected function schedule(Schedule $schedule)
{
$schedule->command('word:add')->everyMinute();
}
I have setup cron job in CPanel.
Command Setting : Once per minute.
Command added as :
/usr/local/bin/php /home/username/public_html/sitename/projectPath &&
php artisan schedule:run >> /dev/null 2>&1
But it is not working - i.e. not adding row to database table neither I am getting any error from in CPanel for cron job. am I missing anything or I am doing something wrong with it?
I have figure out the problem.
for this case, we need to give path of artisan file, so the command would be
* * * * * /usr/local/bin/php /home/username/public_html/sitename/projectPath/artisan schedule:run >> /dev/null 2>&1

Cronjob command not working, despite having the same format as other commands that DO work

Trying to add a new cronjob to my server using Plesk. I have two running already, but it's so long since I set them up that I can't remember why I did it the way I did. They work exactly as they should.
*/13* * * * &> /dev/null php -q httpdocs/forum/notifyreply.php
*/9 * * * * &> /dev/null php -q httpdocs/forum/notifytopic.php
However, when I add my new job using the same format, it doesn't seem to do anything. The script doesn't run and I get no e-mail notification to tell me that the script has run. The new job is as follows:
* * * * * &> /dev/null php -q httpdocs/crm/autoMessages/autoEmail.php
I'm running these on a Linux Virtual Server with Apache and using Plesk Control Panel. Hosting provider is 123-Reg.
Can anyone help?
Thanks!
UPDATE
So I've now removed the /dev/null line so I receive e-mail notifications and I'm getting the following error message:
/bin/sh: php: Permission denied
What I don't understand is why permission is being denied on this command but not on the other two...
Not sure what could have happened, but first thing I would do is to check if the permissions for the new php script are the same as what the old ones have. Do a ls -l on both httpdocs/forum/notifyreply.php and httpdocs/forum/notifytopic.php, and compare the permissions against what httpdocs/crm/autoMessages/autoEmail.php have.
You are not setting a User/Group for the cron command, better do it like this
* * * * * www-data www-data php -q httpdocs/crm/autoMessages/autoEmail.php > /dev/null 2>&1
(assuming that www-data is the correct User)
note that I put the error handling at the end.
Also, I think that you should use the full path; either you forgot to add a slash ( /httpdocs/.... ) , or do you have this script in the cron folder?

Cron Job Commands not working

I am new to cron jobs and have set up one in Plesk to execute every minute however I am not sure if the command is correct due to it not working.
curl http://www.yourdomain.com/twitter_cron.php
I am running on a Centos VPS - the problem is I am not sure if I need a specific root to curl.
sgeorge-mn:~ sgeorge$ which curl
/usr/bin/curl
You need to use full path in cron for curl; otherwise you need to have proper PATH variable specified in crontab
So for example:
* * * * * /usr/bin/curl http://www.yourdomain.com/twitter_cron.php

Resources