Register

How to Create and Manage Cron Jobs in Hestia Control Panel

Updated 2 days ago 5 views

Knowledge Base: How to Create and Manage Cron Jobs in Hestia Control Panel

 

Beginner Friendly / Hestia Control Panel

1. What is a Cron Job?

A cron job is an automated task that runs on your hosting account at a specific time or interval.

Cron jobs allow you to automate repetitive tasks without manually opening your website or running commands.

For example, you can use cron jobs to:

  • Automatically run PHP scripts.
  • Send scheduled emails and notifications.
  • Clean temporary files and application caches.
  • Generate reports and process queued tasks.
  • Perform database backups.
  • Run Laravel scheduled tasks.
  • Update website content automatically.
  • Execute maintenance scripts.

Example: If you have a PHP script that sends reminders, you can configure a cron job to execute it every day at 8:00 AM.

2. Understanding the Add Cron Job Form

When adding a cron job in Hestia Control Panel, you will see the following fields:

Field Description
Command The command or script you want to execute.
Minute The minute when the task should run.
Hour The hour when the task should run.
Day The day of the month.
Month The month when the task should run.
Day of Week The day of the week when the task should run.

Hestia also provides quick scheduling options such as Minutes, Hourly, Daily, Weekly and Monthly, making it easier to configure common schedules.

3. Understanding Cron Job Scheduling Syntax

Cron jobs use five scheduling fields to determine when a command should execute.

Symbol Meaning Example
* Every possible value Every minute
*/5 Every 5 units Every 5 minutes
1,5,10 Specific values Minutes 1, 5 and 10
1-5 A range of values Monday to Friday (day-of-week field)

Examples of scheduling:

Schedule Minute Hour Day Month Day of Week
Every minute * * * * *
Every 5 minutes */5 * * * *
Every 15 minutes */15 * * * *
Every 30 minutes */30 * * * *
Every hour 0 * * * *
Every day at midnight 0 0 * * *
Every day at 8 AM 0 8 * * *
Every Sunday at midnight 0 0 * * 0
First day of every month 0 0 1 * *

Important: Cron uses a 24-hour clock. For example, 2 PM is represented as 14, while 8 PM is represented as 20.

4. How to Create Your First Cron Job

Follow these steps to create a cron job in Hestia Control Panel.

  1. Log in to your Hestia Control Panel.
  2. Navigate to CRON from the dashboard.
  3. Click Add Cron Job.
  4. Enter the command you want to execute.
  5. Configure the Minute, Hour, Day, Month and Day of Week fields.
  6. Alternatively, select one of the predefined scheduling options.
  7. Review your configuration.
  8. Save the cron job.

Your cron job will now execute automatically according to the schedule you configured.

5. Common Cron Job Examples

Below are some practical examples you can use on your hosting account.

Example 1: Run a PHP Script Every 5 Minutes

Suppose your website contains a PHP script named cron.php.

Command:

/usr/bin/php /home/USERNAME/web/yourdomain.com/public_html/cron.php

Schedule:

Minute Hour Day Month Day of Week
*/5 * * * *

Replace USERNAME with your Hestia account username and yourdomain.com with your actual domain.

Example 2: Run a PHP Script Every Day at Midnight

Command:

/usr/bin/php /home/USERNAME/web/yourdomain.com/public_html/backup.php

Schedule:

Minute Hour Day Month Day of Week
0 0 * * *

Example 3: Run a Script Every Hour

Command:

/usr/bin/php /home/USERNAME/web/yourdomain.com/public_html/process.php

Schedule:

Minute Hour Day Month Day of Week
0 * * * *

Example 4: Run a Script Every Sunday

Command:

/usr/bin/php /home/USERNAME/web/yourdomain.com/public_html/weekly.php

Schedule:

Minute Hour Day Month Day of Week
0 0 * * 0

Example 5: Run a Script on the First Day of Every Month

Command:

/usr/bin/php /home/USERNAME/web/yourdomain.com/public_html/monthly.php

Schedule:

Minute Hour Day Month Day of Week
0 0 1 * *

Note: The PHP executable path may differ depending on the server configuration. Confirm the correct PHP CLI path before using these commands.

6. Laravel Application Cron Jobs

If you host a Laravel application, you can configure a cron job to execute Laravel's task scheduler.

Instead of manually scheduling individual tasks, Laravel allows you to define scheduled tasks inside your application.

Command:

cd /home/USERNAME/web/yourdomain.com/public_html && /usr/bin/php artisan schedule:run

Schedule:

Minute Hour Day Month Day of Week
* * * * *

This allows Laravel to check and execute scheduled tasks every minute.

7. WordPress Cron Jobs

WordPress normally uses its internal WP-Cron system, which relies on website visits to trigger scheduled tasks.

For websites with low traffic or where more reliable scheduling is required, you can configure a real server cron job.

Command:

/usr/bin/php /home/USERNAME/web/yourdomain.com/public_html/wp-cron.php

Schedule:

Minute Hour Day Month Day of Week
*/5 * * * *

For this setup, you should disable WordPress's default page-load-triggered WP-Cron by adding the following line to wp-config.php:

define('DISABLE_WP_CRON', true);

This prevents WordPress from relying on visitor traffic to trigger scheduled tasks.

8. Important Things to Know Before Creating Cron Jobs

To ensure your cron jobs work correctly, follow these recommendations:

  • Use absolute paths: Always use the full path to your PHP script, application or executable.
  • Check PHP CLI: Ensure that the PHP command points to an installed PHP CLI version compatible with your application.
  • Check file permissions: Your script must have the necessary permissions to execute.
  • Avoid unnecessary frequency: Do not run resource-intensive scripts every minute unless required.
  • Prevent overlapping tasks: Ensure that a previous execution has finished before another instance starts.
  • Check your server time: Cron jobs follow the server's configured time and timezone, not necessarily your computer's local time.
  • Test your commands: Run your command manually where SSH access is available before scheduling it.
  • Monitor application logs: Check your application logs if a cron job does not work as expected.

9. Troubleshooting Cron Jobs

If your cron job is not executing as expected, check the following:

Problem Possible Solution
Cron job does not execute Check the command and scheduling fields.
PHP script fails Verify the PHP CLI executable path.
Permission denied Check file and directory permissions.
Script cannot find files Use absolute file paths instead of relative paths.
Cron job executes at the wrong time Check the server timezone.
Script runs multiple times Check execution duration and prevent overlapping processes.
No output is displayed Redirect output to a log file for debugging.

Useful debugging command:

You can redirect the output of your cron job to a log file:

/usr/bin/php /home/USERNAME/web/yourdomain.com/public_html/cron.php >> /home/USERNAME/cron.log 2>&1

This saves both normal output and error messages into cron.log, making it easier to identify problems.

10. How to Edit or Delete a Cron Job

You can manage your existing cron jobs directly from Hestia Control Panel.

  • Edit: Open the CRON section, locate the cron job and use its edit option to modify the command or schedule.
  • Delete: Locate the cron job you no longer need and use the delete option.

Always double-check before deleting a cron job because some applications depend on scheduled tasks to operate correctly.

11. Frequently Asked Questions

Q: Can I run multiple cron jobs on my hosting account?

Yes. You can create multiple cron jobs for different scripts and applications, subject to your hosting plan's resource limits and server policies.

Q: Can I execute a PHP script every minute?

Yes. Set the Minute field to * and leave the other scheduling fields as *.

Q: Do cron jobs run when nobody visits my website?

Yes. Server cron jobs execute independently of website traffic.

Q: Can I use cron jobs for database backups?

Yes. You can schedule scripts or commands that perform database backups, provided the necessary permissions and utilities are available.

Q: Why is my cron job not working?

Common reasons include incorrect command paths, PHP version incompatibility, insufficient permissions, incorrect scheduling settings or application errors.

Q: Does my computer need to remain switched on?

No. Cron jobs execute on the hosting server, so your computer does not need to remain online.

Q: What does * * * * * mean?

It means the scheduled command will run every minute.

12. Need Further Assistance?

If you have configured your cron job correctly but it is still not executing, contact the NetrillerHost Support Team.

Please provide:

  • Your domain name.
  • The command configured in your cron job.
  • Your selected scheduling settings.
  • Any error messages or relevant log output.

Our support team will help investigate the issue.

Netriller Host – Hosting & Digital Solutions

Still need help?

If this article did not answer your question, our support team can help.

Contact support
Netriller Host
Top