Setting Up Cron Jobs in DirectAdmin
Cron jobs allow you to schedule commands or scripts to run automatically at specified intervals. This is useful for tasks like database backups, sending scheduled emails, clearing cache files, or running maintenance scripts.
Accessing Cron Jobs
- Log in to your DirectAdmin control panel
- Navigate to Advanced Features in the menu
- Click Cron Jobs
Creating a New Cron Job
Step 1: Set the Schedule
Each cron job requires five time fields:
| Field | Allowed Values | Description |
|---|---|---|
| Minute | 0-59 | Minute of the hour |
| Hour | 0-23 | Hour of the day (24-hour format) |
| Day of Month | 1-31 | Day of the month |
| Month | 1-12 | Month of the year |
| Day of Week | 0-6 | Day of the week (0 = Sunday) |
Use * to match all values. For example, * in the Hour field means "every hour."
Step 2: Enter the Command
In the Command field, enter the full path to your script or command:
/usr/local/bin/php /home/username/domains/yourdomain.com/public_html/cron.phpTip: Always use the full path to both the interpreter (like
/usr/local/bin/php) and your script. Cron jobs do not use the same environment as your shell.
Step 3: Save
Click Add to create the cron job. It will appear in the list below.
Common Schedule Examples
| Schedule | Minute | Hour | Day | Month | Weekday | Description |
|---|---|---|---|---|---|---|
| Every 5 minutes | */5 | * | * | * | * | Runs every 5 minutes |
| Once daily at midnight | 0 | 0 | * | * | * | Runs at 12:00 AM |
| Every Monday at 3 AM | 0 | 3 | * | * | 1 | Weekly on Monday |
| First of every month | 0 | 0 | 1 | * | * | Monthly at midnight |
| Every 30 minutes | */30 | * | * | * | * | Runs twice per hour |
Email Notifications
By default, cron sends the output of each job to your email. To suppress email output, append >/dev/null 2>&1 to your command:
/usr/local/bin/php /home/username/cron.php >/dev/null 2>&1To send output to a log file instead:
/usr/local/bin/php /home/username/cron.php >> /home/username/cron.log 2>&1Editing and Deleting Cron Jobs
- To edit a cron job, delete the existing one and create a new one with the updated settings
- To delete a cron job, click the Delete button next to the job in the list
Troubleshooting
Cron Job Not Running
- Verify the script path is correct and the file exists
- Check file permissions — the script must be readable and executable
- Ensure the PHP or interpreter path is correct (use
which phpvia SSH to find it) - Check the cron log or your email for error messages
Permission Denied Errors
- Make your script executable:
chmod +x /home/username/script.sh - Ensure the script is owned by your user account
Script Runs in Browser but Not via Cron
- Cron does not load your web server environment. Use full paths for all file includes and requires in your script.
- Set the working directory at the start of your script if it depends on relative paths.
Related Articles
Need help with cron jobs? Contact our support team at {{SUPPORT_EMAIL}} or open a ticket at {{SUPPORT_URL}}.