StarDomain

How to Set Up a Cron Job

How to Set Up a Cron Job

Cron jobs are scheduled tasks that run automatically at specified intervals. Common uses include sending email digests, cleaning up temporary files, running database maintenance, and triggering WordPress cron events.

Setting Up Cron Jobs in cPanel

  1. Log in to cPanel.
  2. Go to Advanced > Cron Jobs.

[screenshot: cPanel Cron Jobs page]

Quick Presets

cPanel provides common schedule presets:

  • Once per minute (`* * * * *`)
  • Once per five minutes (`*/5 * * * *`)
  • Once per hour (`0 * * * *`)
  • Once per day (`0 0 * * *`)
  • Once per week (`0 0 * * 0`)
  • Once per month (`0 0 1 * *`)

Creating a Cron Job

  1. Select a Common Setting preset or enter custom timing.
  2. In the Command field, enter your script command.
  3. Click Add New Cron Job.

Common Commands

#### Run a PHP Script

/usr/local/bin/php /home/username/public_html/cron.php

#### Run WordPress Cron

/usr/local/bin/php /home/username/public_html/wp-cron.php

#### Curl a URL

/usr/bin/curl -s https://yourdomain.com/cron-endpoint > /dev/null 2>&1

Tip: Add `> /dev/null 2>&1` at the end of commands to suppress output. Without this, cPanel sends you an email for every cron execution.

Setting Up Cron Jobs in DirectAdmin

  1. Log in to DirectAdmin.
  2. Go to Extra Features > Cron Jobs.
  3. Enter the schedule (minute, hour, day, month, weekday).
  4. Enter the command.
  5. Click Add.

Cron Schedule Format

* * * * *
| | | | |
| | | | └── Day of week (0-7, 0 and 7 = Sunday)
| | | └──── Month (1-12)
| | └────── Day of month (1-31)
| └──────── Hour (0-23)
└────────── Minute (0-59)

Examples

ScheduleMeaning
`0 */6 * * *`Every 6 hours
`30 2 * * *`Daily at 2:30 AM
`0 9 * * 1`Every Monday at 9 AM
`0 0 1 * *`First day of every month at midnight
`*/15 * * * *`Every 15 minutes

Managing Cron Jobs

Editing

  1. Go to Cron Jobs.
  2. Find the job in the list.
  3. Click Edit.
  4. Modify the schedule or command.
  5. Save.

Deleting

  1. Click Delete or Remove next to the cron job.
  2. Confirm deletion.

Best Practices

  1. Test your command first — run it manually via SSH or Terminal to ensure it works.
  2. Suppress output — use `> /dev/null 2>&1` to avoid email spam.
  3. Use full paths — always use absolute paths for PHP, scripts, and files.
  4. Be careful with frequency — running crons too often wastes resources.
  5. Log output — redirect to a log file for debugging: `>> /home/user/cron.log 2>&1`

Warning: Resource-intensive cron jobs (database operations, large file processing) can affect your hosting performance. Schedule them during off-peak hours.


Need help? Contact our support team at {{SUPPORT_URL}}/client/support.