Add a Cron Job in cPanel
Author: admin admin Reference Number: AA-00306 Views: 49549 Created: 2013-04-02 13:38 Last Updated: 2025-08-12 11:13 0 Rating/ Voters

KB: How to Create a Cron Job in cPanel

A cron job is a command that schedules scripts or commands to run automatically on your server at a specified time and date. This is useful for automating repetitive tasks like backups, sending newsletters, or cleaning up temporary files. Here is a guide on how to create a cron job in cPanel.


Step 1: Access the Cron Jobs Interface

  1. Log in to your cPanel account.

  2. In the Advanced section, click on the Cron Jobs icon.


Step 2: Configure the Cron Job Schedule

In the Add New Cron Job section, you will define the schedule for your task. You can use the "Common Settings" dropdown to choose a predefined schedule, or you can manually set the time using the fields for Minute, Hour, Day, Month, and Weekday.

  • Minute: (0-59)

  • Hour: (0-23)

  • Day: (1-31)

  • Month: (1-12)

  • Weekday: (0-6, where 0 is Sunday)

For example, to run a script every day at 3:00 AM, you would set:

  • Minute: 0

  • Hour: 3

  • Day: * (every day)

  • Month: * (every month)

  • Weekday: * (every day of the week)


Step 3: Enter the Command

In the Command field, enter the command you want to execute. The command needs to specify the program to run and the path to your script. Below are two common examples.

Example 1: Executing a PHP Script

To run a PHP script directly on the server, use the PHP interpreter path followed by the script's path. This method is efficient as it doesn't involve a web server request. Replace /home/youruser/script.php with the actual path to your PHP file.

/usr/bin/php /home/youruser/script.php

Example 2: Running a Script as a Browser Would

If your script requires a web server environment or is designed to be executed as if a browser were visiting it, you can use a command-line browser like lynx. This is useful for scripts that rely on a browser's context or a specific web URL.

/usr/bin/lynx --dump https://yourdomain.com/script.php

Step 4: Add the Cron Job

After setting the schedule and entering the command, click the Add New Cron Job button. The cron job will now be active and will run according to your specified schedule.

You can view all your active cron jobs in the Current Cron Jobs section. From there, you can edit or delete them as needed.

Quick Jump Menu