Creating Cron Job on cPanel for Task Scheduling in Laravel - php

Pretty much the title. I am doing it as it says in the docs but it won't work. No log updates in laravel.log file either which might have helped. This is how I set up my cron job:
I also gave it my mail address where it should send the log of the job and it sometimes does do that but sometimes doesn't which I didn't quite understand why. Anyway, the mail content was simply what Laravel says when you type php artisan in the terminal. Like it shows you all the commands of Laravel.
Any idea why it doesn't work and how to fix it? Thanks!

You should to change the line of command to this:
/usr/local/bin/php /home/cpanel-user/laravel-app/artisan schedule:run >> /dev/null 2>&1

Related

Laravel cron on Digitalocean

I have set up Laravel scheduler to run my custom commands at specific time. Now I wanted to set up cron on Digitalocean server to trigger schedule:run each minute to check if something is scheduled at the given time.
After initial SSH-ing to server, I have run crontab -e and added the following line to it:
* * * * * php /var/www/Laravel artisan schedule:run >> laravel_cron.log
but the problem I'm facing is that I don't see anything written in laravel_cron.log, but it does get created, so now I have no idea whether my commands will actually be ran.
To test it out, I have tried entering php /var/www/Laravel artisan but I get no output in command line.
If I change the route to say xyz/www/Laravel it is saying that it can't find it, so I guess the route is set up fine. Also when I manually go to the Laravel folder and run php artisan without the route in the middle, I get the standard output.
I believe the command php /path/ artisan schedule:run does not return any output.
If you want to log the output of a task, you can use sendOutputTo or emailOutputTo
e.g.
$schedule->command('foo')
->daily()
->sendOutputTo($filePath)
->emailOutputTo('foo#example.com');
More examples can be found here

Laravel 5 How to run a php file via scheduler

First time ever setting up a cron/scheduler. How do I run a php file with the scheduler? This is what I see in Laravel's documentation...
Entered the following command via Putty/SSH...
php /path/to/artisan schedule:run >> /dev/null 2>&1
Now... In the Kernel.php file... do I simply add the path to the php file that I want to run in the statement below?
$schedule->exec('node /home/forge/script.js')->daily();
After a few days... I have it working.
I set up the cron job in my cpanel. I set it up to run every minute so I could get good feedback on what I was doing wrong. I created a text file to record the errors.
php /home/accountname/artisan schedule:run >> /home/accountname/cron-output.txt 2>&1
I thought I had to call the php file where the method was located. However, to call a method, you must put the full path to the method like so...
$schedule->call('App\Http\Controllers\ParseDataFeed#parseFeed')
->dailyAt('15:00')
->sendOutputTo('cron-output.txt');
I hope this helps someone.

How to run console command of Yii2 using cron job in Godaddy web hosting server

From localhost am using this command to run and its working succesfully
c:/wamp/www/yii2_advanced>yii test/pending
While am using below command in cron job of godaddy server. its not working
php public_html/yii2_advanced/ yii test/pending >/dev/null 2>&1
So how can I run console command of Yii2 using cron job in Godaddy web hosting server?
Thanks in Advance...
I know this is an old post but I have also waste my whole day to figure out this problem.that is why I am posting my answer.Hope this will help some one.
1> Enter an email id in above section. It will help you to test.
2> Do not choose time less then 5 minutes.Sometimes it is not working on godaddy.
Note: email could take up to 20 minutes to trigger, so be patient.
3>Enter This command after selecting time 5 minutes to test.
/usr/local/bin/php -q /home/username/public_html/projectName/yii json/start
4>Check your email in order to test your job .If job is not working then here will be an error message.
5> When your cron job is up and running then you do not need any email . To remove email sending add this command
/usr/local/bin/php -q /home/username/public_html/projectName/yii json/start >/dev/null 2>&1
You can use below function in crontab
* * * * * php /var/www/html/your-project-path/yii test/index
Here yii points to your root yii file of your Yii project test is my console controller and /index is my method.
Hope this helps .
Non of these answers work for me. Im using yii2 Hope my solution help someone!
First of all Create your Cron as a new file: MyCronNameController.php
We will suppose our cron file name is HelloController.php so it codes will look like:
<?php
namespace app\commands;
use yii\console\Controller;
class HelloController extends Controller
{
public function actionIndex($message = 'hello world')
{
echo $message . "\n";
}
}
One this file is on your hosting, just go to the Cron Job manager into GoDaddy and set the command like this:
/usr/local/bin/php -q /home/<user>/public_html/<project-folder>/yii hello
Take a look that on the command i just run the command without the "Controller" word.
One more observation is that i try this with a cron name like "HelloWordController" and run it with "helloword", and it didnt work, with only one word name it will work ok.
cronjobs in yii2 ubuntu
#create cronjob every minutes
php /var/www/html/yiitest2.0.39/yii test/makefile
https://youtu.be/5KUMNPKgvnU
/usr/local/bin/php -q /public_html/<YOUR_PROJECT_FOLDER_NAME> yii <CONTROLLER_NAME>/<ACTION_NAME>

How to run a PHP script using a DreamHost Cron Job

I have a php script that I'd like to run everyday on my DreamHost website using a cron job. I've tested the script manually so I know it works properly.
I've tried setting up the cron job with this command line:
/usr/bin/wget -O /dev/null "http://www.mysite.org/cronjobs/cronjob.php"
along with a few other methods including this one as well:
/dh/cgi-system/php54.cgi /home/username/mysite.org/cronjobs/cronjob.php
None of these have worked and even worse, I have not received any email with the results so I have no way of knowing what went wrong.
Any idea you may have as to what isn't working would be great!
Try this command in the cpanel.
/usr/local/php5/bin/php /home/username/mysite.org/cronjobs/cronjob.php
It's been a while but since here is still no "solution" for users that might look here for a wget example here is how it works at DreamHost:
wget -q -O /dev/null http://www.domain.com/path-to-be-called

Cannot execute crontab command from a php script...from shared host

I'm running an application where I need to execute the cron job, once a form is submitted,contains more than 1 lac records in a loop(its on-demand execution of cron job and deletes the job once finished).
I'm using php, I tried to configure the job through cpanel as a test and it works...the command was.."/ramdisk/bin/php5 -f /home/user/public_html/domain/cron.php -q", it worked fine.
But when I tried to run the same job with the exec() of php, like I wrote this whole command to a file (I do not know where the original crontab file is located otherwise could have written to it, please suggest a way to find its location) and ran that file like "exec("crontab /home/user/cron/Feed_cron"); ", in this cron is not working...
I doubted whether the crontab command will not work for particular user.. I tried it from the "root" user....which is the root user....tried the command via SSH or Putty and the response was "command not found". Please find a solution for this, also please give me an idea whether my concept works fine...
please suggest a way to find its location
Try
whereis crontab

Categories