php – 如何在hostgator托管服务器cpanel上的cron作业上运行laravel 5.2 artisan命令?

前端之家收集整理的这篇文章主要介绍了php – 如何在hostgator托管服务器cpanel上的cron作业上运行laravel 5.2 artisan命令?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我创建了一个示例计划作业,在Laravel 5.2中的特定时间之后运行.这通过artisan命令在localhost上正常工作.

我在本地服务器上运行此命令:
PHP artisan演示:Cron

现在我在HostGator托管服务器上的cPanel的高级选项cron作业中添加此任务.但它没有用.

这是我正在尝试的命令:

cd / home / pofindia / public_html / beta-var1 /&& /usr/local/bin / PHP artisan演示:Cron

PHP版本:5.4默认.
这是我的示例文件

<?PHP

namespace App\Console\Commands;

use Illuminate\Console\Command;
use DB;

class DemoCron extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'demo:cron';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        DB::table('items')->insert(['name'=>'hello new']);
        $this->info('Demo:Cron Cummand Run successfully!');
    }
}

解决方法

which PHP

要查看PHP可执行文件的位置,请复制该路径.

crontab -e

(我假设这是你的工匠所在的项目根目录/ home / pofindia / public_html / beta-var1 /但是这需要你添加工匠,因为/ home / pofindia / public_html / beta-var1 / artisan )

添加crontab条目

* * * * * /usr/local/bin/PHP  /home/pofindia/public_html/beta-var1/artisan Demo:Cron

你真正在这里做的就是提供绝对的路径

猜你在找的Laravel相关文章