How to Run CRON Job on LIVE SERVER on Cpanel in Laravel Project
You can create a command and schedule command in kernel.php file and create a cron job on live server to run that specific command in laravel project.
1. Create command in laravel\app\Console\Commands directory using php artisan command.
php artisan make:command LoginfoCommand
2. Make changes in file as per your requirments.
laravel\app\Console\Commands\LoginfoCommand.php
<?php
namespace App\Console\Commands;
use Illuminate\Support\Facades\Log;
use Illuminate\Console\Command;
class LoginfoCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'log:run';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Run a log command';
/**
* Execute the console command.
*/
public function handle()
{
Log::info('Laravel schedular run successfully!');
}
}
3. Open kernel.php file and make changes as per below code.
laravel\app\Console\Kernel.php
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* Define the application's command schedule.
*/
protected function schedule(Schedule $schedule): void
{
// $schedule->command('inspire')->hourly();
$schedule->command('log:run')->everyMinute();
}
/**
* Register the commands for the application.
*/
protected function commands(): void
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}
4. Login to cpanel and search for cron jobs and paste below text to command input field and hit add new cron job button. Don't forgot to change your laravel project folder path as per your project directory structure.
/usr/local/bin/php /home/user/public_html/artisan log:run >/dev/null 2>&1
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Laravel
- How to display user profile after login in laravel
- Display option of select as selected with blade directive Laravel
- How to send email in Laravel 11
- How to automatically update the timestamp of parent model in Laravel
- How to display validation error in laravel
- Trying to get property 'title' of non-object
- How to make Copy or Duplicate table row in laravel
- How to get column names from table in Laravel
- Global scope in Laravel with example
- The openssl extension is required for SSL/TLS protection but is not available
- Display first n record from collection in laravel view
- How to validate form input data in laravel
- Remove public from url in laravel project
- How to get last month records in Laravel
- Ajax POST request in laravel
- How to pass query string with pagination in laravel
- SQLSTATE[42000]: Syntax error or access violation: 1055
- Route not defined in Laravel
- How to send ID to another page in Laravel
- How to remove package from laravel
- How to get database name in Laravel 9 ?
- Create project table with model and migration
- How to display pivot table column value in laravel
- Call to a member function pluck() on null
- Laravel append URI in route