
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 get only time from created_at in laravel
- How to check records exist in loaded relationship in Laravel blade view
- Method Illuminate\Http\Request::validated does not exist
- How to add unique records in pivot columns of Laravel pivot table
- How to display validation error in laravel
- On delete set foreign id column value null using migration in laravel 8
- Laravel upload file with original file name
- Include External CSS and JS file in Laravel
- Cannot end a section without first starting one
- SQLSTATE[42S22]: Column not found: 1054 Unknown column 'users.post_id' in 'where clause
- Get previous date data in laravel
- Ajax POST request in laravel
- Call to a member function getRelationExistenceQuery() on array in Laravel
- Target class [admin] does not exist.
- Connection could not be established with host smtp.gmail.com :stream_socket_client(): unable to connect to tcp://smtp.gmail.com:587 (Connection refused)"
- The use statement with non-compound name 'Auth' has no effect
- Order by multiple columns in Laravel
- Create record with unique slug in laravel
- How to return a column with different name in Laravel
- Submit form without CSRF token in Laravel
- Global scope in Laravel with example
- Laravel route redirect not working
- Array to string conversion laravel blade
- How to get the id of last record from collection object in laravel view
- Split an Eloquent Collection by half in Laravel