Hosting

Setting Up Cron Jobs on DirectAdmin Hosting
for Automation

📅 November 3, 2026 âąī¸ 12 min read đŸˇī¸ Cron Job DirectAdmin Automation
Setting Up Cron Jobs on DirectAdmin Hosting for Automation

What is a Cron Job and Why Does It Matter

A Cron Job is a time-based task scheduler on Linux servers that automatically executes scripts or commands at specified intervals. The name comes from Chronos (Greek god of time), and "crontab" is the configuration file that stores the schedule.

On web hosting, Cron Jobs are invaluable for automating repetitive tasks — backing up a database every night, sending weekly reports, clearing cache files, or syncing data from external APIs without any manual intervention.

✅ Common uses for Cron Jobs on hosting:
  • Automated MySQL database backup every night at 02:00
  • Send email newsletter every Monday at 09:00
  • Delete session/tmp files older than 7 days
  • Fetch data from external APIs every 30 minutes
  • Regenerate sitemap.xml every 6 hours

On AsiaGB Hosting powered by DirectAdmin, you can configure Cron Jobs directly from the control panel GUI — no SSH or manual crontab editing required.

Understanding Cron Syntax

Cron syntax consists of 5 time fields followed by the command to execute. Each field represents a different time unit:

* * * * *  /path/to/command
│ │ │ │ │
│ │ │ │ └── Day of week (0-7) (0 and 7 = Sunday)
│ │ │ └──── Month (1-12)
│ │ └────── Day of month (1-31)
│ └──────── Hour (0-23)
└────────── Minute (0-59)

Special Characters in Cron

Setting Up Cron Jobs in DirectAdmin

Configuring a Cron Job in DirectAdmin is straightforward. Follow these steps:

  1. Log in to DirectAdmin Panel at yourdomain.com:2222
  2. Navigate to Advanced Features
  3. Click Cron Jobs
  4. Fill in the Minute, Hour, Day, Month, Weekday fields
  5. Enter your command in the Command field
  6. Click Add to save
💡 Tip: DirectAdmin can send an email notification when a Cron Job runs. This is helpful for debugging. If you don't want emails on every run, append >/dev/null 2>&1 to your command to suppress all output.

Running PHP Scripts via Cron

There are two main ways to execute PHP scripts from Cron: PHP CLI and curl/wget:

Method 1: PHP CLI (Recommended)

/usr/local/bin/php /home/USERNAME/public_html/cron/backup.php

Replace USERNAME with your DirectAdmin account name and adjust the script path accordingly.

Method 2: Curl to URL

curl -s https://yourdomain.com/cron/backup.php > /dev/null 2>&1

Simpler but be mindful of security since the URL is publicly accessible.

Finding PHP Path on DirectAdmin

If you're unsure about the PHP binary path, common locations are:

Common Use Cases on Hosting

1. Nightly MySQL Database Backup

0 2 * * * /usr/local/bin/php /home/USERNAME/public_html/backup-db.php

Runs every day at 02:00 — ideal for low-traffic hours.

2. Weekly Email Newsletter

0 9 * * 1 /usr/local/bin/php /home/USERNAME/public_html/send-newsletter.php

Runs every Monday at 09:00.

3. Clear Old Cache Files

0 */6 * * * /usr/bin/find /home/USERNAME/public_html/cache/ -mtime +7 -delete

Runs every 6 hours, deletes files older than 7 days.

4. WordPress WP-Cron

*/15 * * * * /usr/local/bin/php /home/USERNAME/public_html/wp-cron.php > /dev/null 2>&1

Run WP-Cron every 15 minutes. Recommended to disable WordPress's built-in WP-Cron and use this server-side alternative for better performance.

5. Regenerate Sitemap

0 */6 * * * /usr/local/bin/php /home/USERNAME/public_html/sitemap-generate.php

Regenerate sitemap every 6 hours so search engines always get fresh data.

Cron Syntax Reference Table

Cron ExpressionMeaningUse Case
* * * * *Every minuteMonitoring / health check
*/5 * * * *Every 5 minutesAPI polling
*/15 * * * *Every 15 minutesWP-Cron
0 * * * *Every hour (at :00)Cache clear
0 */6 * * *Every 6 hoursSitemap regen
0 2 * * *Daily at 02:00Daily backup
0 9 * * 1Monday at 09:00Weekly report
0 0 1 * *1st of every monthMonthly summary
0 0 1,15 * *1st and 15th monthlyTwice-monthly backup
0 8-17 * * 1-5Hourly weekdays 08-17Business hour task

Troubleshooting Cron Jobs

If your Cron Job is not running as expected, troubleshoot in this order:

1. Check Full Paths

Cron runs in a minimal environment where $PATH is not set the same as your login shell. Always use absolute paths:

# ❌ May fail
php /home/user/backup.php

# ✅ Correct
/usr/local/bin/php /home/user/public_html/backup.php

2. Check File Permissions

chmod 755 /home/USERNAME/public_html/cron/backup.php

Scripts must be executable by the file owner.

3. Check Email Log from Cron

By default, Cron emails any output to the DirectAdmin account email. Check your inbox for error messages when a job runs.

4. Test Script Manually First

/usr/local/bin/php /home/USERNAME/public_html/cron/backup.php

Run the script directly in SSH to confirm it works before scheduling.

5. Verify Server Timezone

âš ī¸ Note: AsiaGB servers run in UTC+7 (Asia/Bangkok), which matches Thailand time. If migrating from another host, verify the timezone matches your expectations.

Best Practices and Caveats

Don't Schedule Too Frequently

A Cron Job that runs every minute and takes 5 minutes to complete will spawn multiple concurrent instances, consuming hosting resources and potentially slowing your website. Only schedule as frequently as your task genuinely requires.

Use Output Redirection

# Keep a log file
0 2 * * * /usr/local/bin/php /home/USER/backup.php >> /home/USER/cron.log 2>&1

# Suppress all output
0 2 * * * /usr/local/bin/php /home/USER/backup.php > /dev/null 2>&1

Test Before Deploying

Always run your script manually first to confirm it completes without errors before adding it as a Cron Job.

Check Resource Limits

Some hosting plans limit the number of Cron Jobs or CPU time per job. Avoid running heavy tasks during peak traffic hours to maintain website performance for visitors.

💡 WordPress tip: Disable the built-in WP-Cron by adding define('DISABLE_WP_CRON', true); to wp-config.php, then set up a real server Cron Job calling wp-cron.php. This is more reliable and doesn't consume PHP resources on every page request.

Frequently Asked Questions

What is a Cron Job?

A Cron Job is a scheduled task on a Linux server that runs automatically at specified intervals, managed by the cron daemon using a crontab configuration file.

Does DirectAdmin support Cron Jobs?

Yes. DirectAdmin has a built-in Cron Jobs manager under Advanced Features. You can add and manage scheduled tasks without editing crontab directly.

What do the 5 fields in a cron expression mean?

The 5 fields represent: minute (0-59), hour (0-23), day of month (1-31), month (1-12), and day of week (0-7). For example, 0 2 * * * means every day at 02:00.

Why is my Cron Job not running?

Common causes are incorrect file paths, missing execute permissions, wrong PHP version path, or syntax errors. Check email notifications from cron and test your script manually first.

Can I run a PHP script with Cron?

Yes. Use /usr/local/bin/php /home/USERNAME/public_html/script.php. Always use the full path for both the PHP binary and your script file.

How often can I run a Cron Job on shared hosting?

Most plans allow every-minute scheduling, but running resource-intensive tasks too frequently can impact server performance. Use the minimum frequency needed for your actual use case.


Want hosting with full Cron Job support via DirectAdmin? View AsiaGB Hosting Plans →