
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
- Target class [HomeController] does not exist
- Laravel get single row by id
- How to call controller function from view in Laravel
- Class App\Http\Controllers\Admin\UserController Does Not Exist
- How to get single column value in laravel
- How to update record after save method in Laravel
- Split an Eloquent Collection by half in Laravel
- Connection could not be established with host smtp.gmail.com :stream_socket_client(): unable to connect to tcp://smtp.gmail.com:587 (Connection refused)"
- How to add class to tr in table using foreach in laravel
- How to randomly get the user id from users table in laravel
- Laravel order by date not working
- How to upload files to amazon s3 bucket using Laravel
- How to send email in Laravel 11
- Delete all related comments on deleting a post in Laravel
- Sample configuration files to create laravel project with docker using wsl (window subsystem linux)
- Convert input array to comma-separated string in laravel controller
- How to insert value to additional columns in pivot table in laravel
- Validation for multiple forms on same page in laravel
- Run artisan command to generate key in laravel
- Global scope in Laravel with example
- Get current URL on visit URL in Laravel
- The openssl extension is required for SSL/TLS protection but is not available
- How to show data by ID in laravel?
- Validation errors for multiple forms on same page Laravel
- Update if exist else insert new record in laravel