Reputation: 996
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...
Upvotes: 0
Views: 4451
Reputation: 209
cronjobs in yii2 ubuntu
#create cronjob every minutes
Upvotes: 0
Reputation: 516
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 .
Upvotes: 1
Reputation: 11
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.
Upvotes: 0
Reputation: 11
/usr/local/bin/php -q /public_html/<YOUR_PROJECT_FOLDER_NAME> yii <CONTROLLER_NAME>/<ACTION_NAME>
Upvotes: -1
Reputation: 1181
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
Upvotes: 1