I want to create a cron job for Laravel 5.2
My shared host (on OVH), only allows me to point to the full path of a file, and I am not able to use the recommended Cron entry from Laravel's docs, ie :
* * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1
Therefore, I have to call the Artisan command from a .php file, outside of the Laravel framework.
Here is what my public/cron.php
file looks like so far:
<?php
require __DIR__.'/../bootstrap/autoload.php';
use Illuminate\Support\Facades\Artisan;
Artisan::call('refresh');
refresh
being my command for regenerating thumbnails inside my app.
When accessing cron.php through my browser (testing on local XAMPP), the following error occurs:
Fatal error: Uncaught RuntimeException: A facade root has not been set. in
C:\xampp\htdocs\site\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php:210
Stack trace:
#0 C:\xampp\htdocs\site\public\cron.php(7): Illuminate\Support\Facades\Facade::__callStatic('call', Array)
#1 {main} thrown in C:\xampp\htdocs\site\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php on line 210
I have also tried to boot the app, but it doesn't make any differences
$app = require_once __DIR__.'/../bootstrap/app.php';
$app->boot();
To avoid using the Artisan Facade, I tried calling the underlying Kernel Class directly:
use Illuminate\Contracts\Console\Kernel;
$kernel = new Kernel;
$kernel->call('refresh');
But this returns:
Uncaught Error: Cannot instantiate interface Illuminate\Contracts\Console\Kernel
EDIT: Here is a screenshot of OVH cron interface. The cron task is customized by OVH and only allows to point to the fullpath uri of a file - which file would execute my artisan command-. My question is, what should I put in this file, and should it be a PHP file, or a CMD?
crontab -e
is just a shortcut to open/var/spool/cron/crontabs/<username>
with favorite text editor. There are many other ways to put some contents in that file. Obviously, a script can handle it too. – Tuckcrontab -e
to run artisan command of you choice using standard syntax and following Laravel documentation. – Tuckwww
folder (for security, because thewww
folder is publicly available frommynickname.cluster005.ovh.net
and I dont want my sites to be available fromwww/site1
,www/site2
...). So I was thinking that maybe only the files insidewww
folder are writable, and maybe not the one outside (at the root)? – Longlimbed