How to Set Up Cron Jobs on DirectAdmin Hosting
Table of Contents
Cron Jobs are one of the most powerful automation tools available on web hosting. From sending emails and backing up databases to clearing cache and fetching API data — Cron Jobs handle repetitive tasks automatically, without manual intervention. This guide covers everything you need to set up Cron Jobs on DirectAdmin hosting.
1. What Is a Cron Job?
A Cron Job is a time-based task scheduler in Unix/Linux systems. The name "Cron" comes from Chronos, the Greek god of time — fitting, since its primary purpose is time-based task scheduling.
The scheduler reads a configuration file called crontab (cron table) that defines which commands to run and when. On DirectAdmin hosting, you can manage Cron Jobs through the control panel without direct server access.
2. Why Use Cron Jobs on Hosting?
Tasks that benefit from automation via Cron Jobs:
- Automated backups — schedule database and file backups
- Email campaigns — trigger newsletter scripts at specific times
- Cache clearing — regularly clean session files and temp data
- Data fetching — pull RSS feeds, exchange rates, or API data
- WordPress Cron — run WP-Cron to publish scheduled posts on time
- Report generation — create daily or weekly analytics reports
- Token renewal — refresh OAuth tokens before they expire
3. Accessing Cron Jobs in DirectAdmin
To open the Cron Jobs section in DirectAdmin:
- Log in to DirectAdmin at
yourdomain.com:2222 - Find the Advanced Features section and click Cron Jobs
- You will see existing Cron Jobs and a form to add new ones
4. Cron Expression Format
A Cron Expression consists of 5 fields separated by spaces:
* * * * * command
│ │ │ │ │
│ │ │ │ └── Day of week (0-7, 0=Sunday)
│ │ │ └──── Month (1-12)
│ │ └────── Day of month (1-31)
│ └──────── Hour (0-23)
└────────── Minute (0-59)
Special characters:
| Character | Meaning | Example |
|---|---|---|
* | Any value | * * * * * = every minute |
, | Multiple values | 0 9,18 * * * = 9 AM and 6 PM |
- | Range | 0 9-17 * * * = every hour 9–17 |
/ | Step | */15 * * * * = every 15 minutes |
5. Common Cron Job Examples
5.1 Run every day at midnight
0 0 * * * /usr/local/bin/php /home/user/public_html/backup.php
5.2 Run every 15 minutes
*/15 * * * * /usr/local/bin/php /home/user/public_html/queue.php
5.3 Run every Monday at 8 AM
0 8 * * 1 /usr/local/bin/php /home/user/public_html/weekly-report.php
5.4 Run on the 1st of every month
0 1 1 * * /usr/local/bin/php /home/user/public_html/monthly-cleanup.php
5.5 Fetch a URL with wget
*/30 * * * * wget -q -O /dev/null https://yourdomain.com/cron/fetch.php
6. Step-by-Step Setup Guide
Steps to add a new Cron Job in DirectAdmin:
- Open the Cron Jobs page in DirectAdmin
- Fill in the Minutes field (e.g.,
0or*/15) - Fill in the Hours field (e.g.,
2for 2 AM) - Fill Day, Month, Weekday as needed (use
*for "every") - Enter the command in the Command field:
/usr/local/bin/php /home/yourusername/public_html/script.php
- Click Add to save
6.1 Finding the Correct PHP Path
Common PHP paths on hosting servers:
| Version | Path |
|---|---|
| PHP 8.3 | /usr/local/php83/bin/php |
| PHP 8.2 | /usr/local/php82/bin/php |
| PHP 8.1 | /usr/local/php81/bin/php |
| Default PHP | /usr/local/bin/php |
Contact hosting support or check DirectAdmin → PHP Selector to confirm the exact PHP path on your server.
7. WordPress Cron Jobs
By default, WordPress uses WP-Cron, which only triggers when someone visits your site. This is unreliable for scheduled posts and resource-intensive. The recommended approach:
7.1 Disable WP-Cron
Add this line to wp-config.php before /* That's all, stop editing! */:
define('DISABLE_WP_CRON', true);
7.2 Set Up a Real Cron Job in DirectAdmin
Add a Cron Job that runs every 5 minutes:
*/5 * * * * /usr/local/bin/php /home/yourusername/public_html/wp-cron.php > /dev/null 2>&1
Or using wget:
*/5 * * * * wget -q -O - https://yourdomain.com/wp-cron.php?doing_wp_cron > /dev/null 2>&1
8. Troubleshooting Cron Jobs
8.1 Capture Cron Output in a Log File
/usr/local/bin/php /home/user/public_html/script.php >> /home/user/cron.log 2>&1
Then view cron.log through the DirectAdmin File Manager.
8.2 Common Problems and Solutions
| Problem | Cause | Solution |
|---|---|---|
| Cron not running | Wrong PHP path | Use full path e.g., /usr/local/bin/php |
| Script error | Code bug | Test the script manually first |
| Permission denied | Wrong chmod | Set chmod 755 script.php |
| Memory limit | Task too heavy | Reduce scope or split into smaller tasks |
| Overlap / concurrent runs | Task takes longer than interval | Add a lock file |
8.3 Lock File to Prevent Concurrent Runs
<?php
$lock = '/tmp/myscript.lock';
if (file_exists($lock)) exit;
touch($lock);
// Your task here
unlink($lock);
?>
9. Cron Expression Reference Table
| Expression | Meaning |
|---|---|
* * * * * | Every minute |
*/5 * * * * | Every 5 minutes |
*/15 * * * * | Every 15 minutes |
0 * * * * | Every hour (at minute 0) |
0 0 * * * | Every day at midnight |
0 2 * * * | Every day at 2:00 AM |
0 8 * * 1 | Every Monday at 8:00 AM |
0 0 1 * * | 1st of every month |
0 0 1,15 * * | 1st and 15th of every month |
0 9-17 * * 1-5 | Hourly during business hours, Mon–Fri |
10. Summary
Cron Jobs on DirectAdmin hosting automate repetitive tasks reliably. Key takeaways:
- Always use the full PHP path in commands
- Redirect output to a log file for debugging
- Disable WP-Cron and use a real Cron Job for WordPress
- Use a lock file to prevent concurrent runs for long-running tasks
- Start with wider intervals and adjust based on your needs
Frequently Asked Questions
0 2 * * * means run every day at 2:00 AM.define('DISABLE_WP_CRON', true); to wp-config.php to disable the built-in WP-Cron, then create a real Cron Job in DirectAdmin to call wp-cron.php every 5–15 minutes.>> /home/user/cron.log 2>&1 to your cron command. This saves both standard output and error output to a log file you can view in DirectAdmin's File Manager.