Laravel 5 Cron Job On Godaddy Hosting - php

Hello and thanks in advance,
I am using Laravel 5 hosted on Godaddy. I am trying to get a cron job to run but I keep getting this message:
Status: 404 Not Found
X-Powered-By: PHP/7.1.11
Content-type: text/html; charset=UTF-8
No input file specified.
I haven't done a cron myself in Laravel before and I decided to follow this tutorial https://scotch.io/#Kidalikevin/how-to-set-up-cron-job-in-laravel
Everything works fine when I run php artisan DeleteInActiveUsers:deleteusers but the Cron doesn't.
Below are the commands I have tried in the Cron, the file name I created based on the tut is called DumpZohoContacts.php.
Note: I have added /usr/bin/php & -q but it still doesn't work I also ran app_path(); to see my app path and check that. And the code is not the issue since it runs fine by itself
Cron Commands:
php /home/[hidden]/public_html/rms/artisan schedule:run
php /home/[hidden]/public_html/artisan schedule:run
php /home/[hidden]/public_html/rms/artisan zohoDumpToDb:dumpContacts
php /home/[hidden]/public_html/artisan zohoDumpToDb:dumpContacts
php /home/[hidden]/public_html/rms/app/Console/Commands/artisan schedule:run
php /home/[hidden]/public_html/rms/app/Console/Commands/artisan zohoDumpToDb:dumpContacts
php /home/[hidden]/public_html/rms/app/Console/Commands/DumpZohoContacts.php

From my Email, I used to get this warning. Iff you have entered an incorrect command
PHP Warning: Module 'magickwand' already loaded in Unknown on line 0
Status: 404 Not Found
X-Powered-By: PHP/5.6.37
Content-type: text/html; charset=UTF-8
No input file specified.
If you are about to schedule the command as once a day (i.e., 00:00) the same time should be reflected in a $schedule->command(); object
In Kernel.php you should specify
/**
* Define the application's command schedule.
*
* #param \Illuminate\Console\Scheduling\Schedule $schedule
* #return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('SyncAPIOrders:orders')
->timezone('Asia/Kolkata')
->dailyAt('00:00');
}
You should add the command from the cPanel server as
/usr/local/bin/php /home/xyz/public_html/artisan schedule:run 1>> /home/xyz/public_html/log_laravel 2>&1
This will keep all the logs in /home/xyz/public_html/log_laravel
Running scheduled command: '/opt/cpanel/ea-php71/root/usr/bin/php' 'artisan' SyncAPIOrders:orders > '/dev/null' 2>&1

Related

Laravel - Task Scheduling

I'm using Laravel 5.4 on a local WAMP Server. I wanted to perform a Task Scheduling but I'm not sure if I really understood how this works.
I created a command cronEmail and in the handle() function added code where I would get an Email.
In Kernel.php I added this:
protected $commands = [
'App\Console\Commands\cronEmail'
];
...
protected function schedule(Schedule $schedule)
{
$schedule->command('send:email')
->everyMinute();
}
So basically I want to get an email every minute. But how do I start this?
I tried entering:
php artisan schedule:run >> /dev/null 2>&1
or even
php C:\wamp64\www\seo-parser\artisan schedule:run >> /dev/null 2>&1
on my cmd but I always get:
The system cannot find the path specified.
If i enter php artisan schedule:run it will actually send an email but only once.
Did I understand the whole concept wrong? How do I do this properly?
Thank you,
Patrick
As stated in the official Laravel documentation you need to add the following line to your crontab.
* * * * * php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1
You do this by typing "crontab -e" in the console. Paste the above line and replace the "/path-to-your-project" with the path to your project.
This results in a cronjob wich calls the "php artisan schedule:run" command every minute.
This requires you to run Linux though. If you need an alternative to crontab when running Windows you can start by reading here.

Scheduling jobs in Laravel

I created a command in laravel "update:date" and "php artisan list" successfully lists it. I am able to execute it using "php artisan update:date"
Kernel.php:
protected $commands = [
'Snuba\Console\Commands\Inspire',
'Snuba\Console\Commands\UpdateDate'
];
protected function schedule(Schedule $schedule)
{
$schedule->command('inspire')
->hourly();
$schedule->command('update:date')
->everyMinute();
}
I configured it to run every minute as given above. Do I need to configure anything else ? I think laravel should automatically register it as cron task on ubuntu server.
I think laravel should automatically register it as cron task on
ubuntu server.
No, you have to start it like:
* * * * * php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1
Starting The Scheduler
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
Reference
Another Answer
I just noticed:
Call to undefined method Illuminate\Console\Scheduling\Event::everyMinute()
I followed the documentation and thought this is a valid method call. I found that everyMinute() is no more valid in laravel 5+. So, I used cron expression instead.
Laravel's command scheduler allows you to fluently and expressively define your command schedule within Laravel itself. For more go through following link laravel task scheduling
If you have access to SSH
run command crontab -e
insert this line:
php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1
which will run all your specified crons as there specified times.
If you have cpanel then under crontab add the above line on command
If ->everyMinute does not exist, please use ->cron('*/1 * * * * *') to set every minute. Or override class laravel.com/api/5.x/Illuminate/Console/Scheduling/Event.html
If cron job not working, run command crontab -e and add this line without single quote
'* * * * * php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1'
After do this I think it works perfectly.

is it possible to change the path to PHP that the Laravel task scheduler uses

I have a Laravel 5.4 app which is on shared hosting and the cron job isn't working. I have set the command up in the kernel.php like so:
$schedule->command('eoddsmaker:get_events')
->withoutOverlapping()
->appendOutputTo(storage_path('logs').'/cron-get_events.log')
->everyMinute();
And if I just run /usr/bin/php-5.6 artisan eoddsmaker:get_events from the command line it runs fine. When it gets called by the cron job though it doesn't run. This is my cron definition:
* * * * * /usr/bin/php-5.6 /var/sites/c/cyo.mydomain.com/artisan schedule:run >> /var/sites/c/cyo.mydomain.com/cron.log 2>&1
I can see from the cron logs on the server that this task is running every minute and everytime that it runs the following output gets added to the cron.log file:
Running scheduled command: '/usr/bin/php' 'artisan' eoddsmaker:get_events > '/dev/null' 2>&1
X-Powered-By: PHP/5.6.8
Content-type: text/html; charset=UTF-8
So to dig a bit deeper if I look in the cron-get_events.log file that I have configured the task to send output to the following gets output every time it runs:
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /var/sites/c/cyo.mydomain.com/artisan on line 31
Parse error: syntax error, unexpected T_STRING in /var/sites/c/cyo.mydomain.com/artisan on line 31
Because I'm on shared hosting the default PHP version is 5.2 and I have to add a rule in the htaccess file to get it to use PHP 5.6. If I forget to add the rule I get the same error as the one that is in the cron-get_events.log so this leads me to believe that the reason the command isn't working is because when the scheduler runs it is calling the command with /usr/bin/php as the path to PHP rather than /usr/bin/php-5.6
Is there a way to configure the task scheduler to use a different path to PHP?
I've managed to solve the problem by changing my scheduler task definition from:
$schedule->command('eoddsmaker:get_events')
->withoutOverlapping()
->appendOutputTo(storage_path('logs').'/cron-get_events.log')
->everyMinute();
To:
$schedule->exec('/usr/bin/php-5.6 /var/sites/c/cyo.mydomain.com/artisan eoddsmaker:get_events >> /var/sites/c/cyo.mydomain.com/cron.log 2>&1')
->withoutOverlapping()
->appendOutputTo(storage_path('logs').'/cron-get_events.log')
->everyMinute();
I'd still be interested to know through if there is a nicer way to achieve this so that I can just declare the path to PHP within Laravel
I ran into this problem as well today and was able to fix it by simply including
PHP_BINARY=/usr/bin/php
in the .env file.

Task schedular of laravel not working properly on server

I am able to execute individual artisan commands on server using putty cli. for eg.
php artisan inspire
and other custom commands related to database, they work fine while using putty. Also i put them in kernel.php 's schedule funtion like this
protected function schedule(Schedule $schedule){
$schedule->command('customcommand:execute')->everyMinute();
}
when i run this command using putty
php artisan schedule:run
it also works fine.
problem is that i am not able to execute schedule:run command via servers cron job.. command looks like this on server
php -d register_argc_argv=On /path/to/artisan schedule:run >> /dev/null 2>&1
funny thing is i am able to execute individual commands via servers cron job
i.e.
php -d register_argc_argv=On /path/to/artisan customcommand:execute >> /dev/null 2>&1
works as well...
only that schedule command is not working.
also it does not show any errors..
also if I dont add '-d register_argc_argv=On', i get exception 'ErrorException' with message 'Invalid argument supplied for foreach()
again here by server i mean cPanal, i have added this command under 'cron jobs'
The ini directive register_argc_argv was disabled on the php.ini and I needed to enable it explicitly on each call in order to accept argc and argv parameters. Luckily I easily solved this problem using exec instead of command
$schedule->exec('php -d register_argc_argv=On /path/to/artisan sms:bulk-send')
Use your command instead of sms:bulk-send Then it will be work.
* * * * * /usr/local/bin/ea-php71 /home/your_domain/artisan schedule:run >> /dev/null 2>&1
first ,
which php
to get which php you're using now
then change your cron job command like
* * * * * /path/to/your/php /path/to/your/project/artisan schedule:run
specify which php and project you are using
for example * * * * * /usr/local/bin/php /home/user/project/artisan schedule:run
it works for me

Laravel scheduled command via CRON not running

I have a Laravel 5.1 site, and an artisan command set up that I can run manually without problems, but I cannot seem to get it to fire at a scheduled time.
I have a crontab set up on a digital ocean server, the contents of the file are
HELL=/bin/bash
MAILTO=""
* * * * * php /var/www/{domain}/artisan schedule:run 1>> /dev/null 2>&1
where {domain} is the actual domain.
In my kernel.php file I have the following
protected function schedule(Schedule $schedule)
{
$schedule->command('migrate:existing-users')->dailyAt('10:25');
}
There's nothing in the laravel log file that offers any clues, it just seems like nothing it happening.
How can I check if the cron is set up correctly?
EDIT:
It seems the cron tab was set up under the root user, so I have also set up another one under www-data, and put this simple line in both
* * * * * echo 'run this command every minute'
with my email address in the MAILTO= line, but nothing gets emailed to me on either crontab

Categories