A cron job automatically executes tasks at scheduled times. In this guide, we explain how to set up cron jobs in DirectAdmin.

What is a cron job?

A cron job (or cron task) is a scheduled task that runs automatically at certain times. Examples:

  • Daily database backup
  • Clear cache every hour
  • Generate weekly report
  • Run scripts periodically

Creating a cron job

Step 1: Navigate to Cron Jobs

  1. Log in to DirectAdmin
  2. Go to Cron Jobs in the menu
  3. You'll see an overview of existing cron jobs

Step 2: Add new cron job

  1. Click Add Cron Job
  2. Fill in the timing (see below)
  3. Fill in the command
  4. Click Add

Configuring timing

A cron job uses 5 time fields:

Field Range Meaning
Minute 0-59 At which minute
Hour 0-23 At which hour
Day 1-31 On which day of month
Month 1-12 In which month
Weekday 0-7 On which day (0=Sunday)

Common schedules

Every minute:

* * * * *

Every hour:

0 * * * *

Every day at 3:00:

0 3 * * *

Every Monday at 9:00:

0 9 * * 1

First day of month:

0 0 1 * *

Command examples

Run WordPress cron

/usr/local/bin/php /home/user/domains/site.com/public_html/wp-cron.php

Run PHP script

/usr/local/bin/php /home/user/domains/site.com/public_html/scripts/backup.php

Database backup

/usr/bin/mysqldump -u user -p'password' database > /home/user/backups/db-$(date +\%Y\%m\%d).sql

Fetch URL (webhook)

/usr/bin/wget -q -O /dev/null https://site.com/cron-endpoint

Managing cron jobs

Edit

  1. Go to Cron Jobs
  2. Click on the cron job
  3. Modify timing or command
  4. Click Save

Disable

Add # at the beginning of the command. The cron job will be skipped but not deleted.

Delete

  1. Go to Cron Jobs
  2. Select the cron job
  3. Click Delete

Output and logging

Output to file

0 3 * * * /usr/local/bin/php /path/to/script.php >> /home/user/logs/cron.log 2>&1

Ignore output

0 3* * * /usr/local/bin/php /path/to/script.php > /dev/null 2>&1

WordPress and cron jobs

WordPress uses wp-cron.php for scheduled tasks. For better performance:

  1. Disable WP-Cron in wp-config.php:
define('DISABLE_WP_CRON', true);
  1. Add a real cron job:
*/15* * * * /usr/local/bin/php /home/user/domains/site.com/public_html/wp-cron.php

Common problems

Cron job not working

  1. Check the path: Use full paths
  2. Check permissions: Script must be executable
  3. Check output: Redirect output to log file
  4. Test manually: Run command via SSH

Wrong PHP version

Specify the PHP version:

/usr/local/bin/ea-php81 /path/to/script.php

Tips

  1. Test manually first: Run command via SSH before creating cron job
  2. Use logging: Redirect output to log file
  3. Not too frequent: Avoid every-minute cron jobs unless needed
  4. Test backup scripts: Verify backups actually work
  5. Use full paths: Prevents "command not found" errors

Need help?

We're here for you! Running into issues or have questions? Our support team is happy to help you personally. Drop us a message through the ticket system - we usually respond within a few hours and love helping you find the best solution.