Set up cron jobs in DirectAdmin
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
- Log in to DirectAdmin
- Go to Cron Jobs in the menu
- You'll see an overview of existing cron jobs
Step 2: Add new cron job
- Click Add Cron Job
- Fill in the timing (see below)
- Fill in the command
- 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
- Go to Cron Jobs
- Click on the cron job
- Modify timing or command
- Click Save
Disable
Add # at the beginning of the command. The cron job will be skipped but not deleted.
Delete
- Go to Cron Jobs
- Select the cron job
- 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:
- Disable WP-Cron in
wp-config.php:
define('DISABLE_WP_CRON', true);
- 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
- Check the path: Use full paths
- Check permissions: Script must be executable
- Check output: Redirect output to log file
- Test manually: Run command via SSH
Wrong PHP version
Specify the PHP version:
/usr/local/bin/ea-php81 /path/to/script.php
Tips
- Test manually first: Run command via SSH before creating cron job
- Use logging: Redirect output to log file
- Not too frequent: Avoid every-minute cron jobs unless needed
- Test backup scripts: Verify backups actually work
- 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.
0 van 0 vonden dit nuttig