How to run cron job on hostinger for laravel
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
# How to Run Laravel Cron Jobs on Hostinger: A Developer's Guide
Setting up scheduled tasks, or cron jobs, is fundamental to any application that relies on background processing, like a Laravel application. When deploying a Laravel project on shared hosting platforms like Hostinger, the method for scheduling these tasks can sometimes be more nuanced than setting up a standard local server setup. As a senior developer, I understand the challenge: ensuring that your Artisan commands execute reliably in an environment where direct SSH access might be limited or complex to configure initially.
This guide will walk you through the correct and most robust ways to schedule your Laravel scheduler on Hostinger, focusing on executing commands like those found in `app/console/commands/realtime.php`.
## Understanding Laravel Scheduling vs. System Cron
Before diving into Hostinger specifics, it's crucial to understand the two layers involved:
1. **Laravel Scheduler:** This is the application-level mechanism defined by the `Kernel.php` file that tells Laravel *what* tasks need to run (e.g., running a specific command every hour).
2. **System Cron:** This is the operating system scheduler (like Linux cron) which executes external commands at specified times.
For a typical shared hosting environment, you cannot simply place a path into the main server crontab and expect Laravel to bootstrap correctly unless you control the entire execution environment. Therefore, we need methods that bridge this gap.
## Method 1: Using Hostinger's Web Cron Feature (The Easiest Route)
Many hosting providers offer a "Web Cron" feature, which allows you to define cron jobs directly within the hosting control panel. This is often the simplest way to trigger tasks on shared hosting where direct SSH management is restricted.
**How it works:** Instead of executing the full Laravel command via the standard system cron, you configure the host's cron job to execute a PHP script that manually bootstraps the Laravel application and runs the Artisan command.
1. **Create a Runner Script:** Create a simple PHP file (e.g., `run_cron.php`) in your public directory or a secure location. This script will handle loading the environment and executing the required command.
```php
getMessage());
}
?>
```
2. **Configure the Hostinger Cron:** Access your Hostinger control panel, find the Cron Job management section, and set a schedule (e.g., run every hour). The command you enter will point to the PHP interpreter executing your runner script:
`* * * * * /usr/bin/php /path/to/your/project/public_html/run_cron.php`
This method ensures that the execution context is handled by the web server environment, which is often more stable on shared hosting than pure system cron calls. This aligns well with best practices outlined by teams focusing on robust application deployment, similar to what we see at [Laravel Company](https://laravelcompany.com).
## Method 2: SSH Execution (The Developer's Preferred Route)
If your Hostinger plan provides SSH access, this is the most powerful and reliable method. This bypasses potential limitations of the Web Cron feature by allowing you to run the command directly in the environment where Composer and Laravel are installed.
You can use standard Linux `crontab` on the server via SSH:
1. **SSH into your Hostinger Server.**
2. **Edit the crontab:** Run `crontab -e`.
3. **Add the entry:** Schedule your command to run at specific times. To ensure the correct environment variables are loaded, you should use the full path to the PHP executable and execute the Artisan command:
```cron
# Runs the realtime job every hour at minute 0
0 * * * * /usr/bin/php /home/user/public_html/artisan schedule:run >> /home/user/cron.log 2>&1
```
This approach gives you granular control over logging and error reporting, which is critical for maintaining complex scheduled tasks. Whenever dealing with deployment and scheduling on shared environments, leveraging access to the command line (via SSH) provides superior debugging capabilities compared to relying solely on web-based triggers.
## Conclusion
For running Laravel scheduler commands on Hostinger, the choice between Web Cron and SSH execution depends entirely on your level of server control. If you are on a stricter shared plan, using a carefully crafted PHP runner script triggered by Web Cron (Method 1) is viable. However, for maximum reliability, detailed logging, and complex scheduling—especially when dealing with commands like those in `app/console/commands/realtime.php`—gaining SSH access and utilizing the standard Linux `crontab` (Method 2) is the definitive senior developer approach. Always prioritize methods that provide clear error logging to ensure your background processes execute exactly as intended.