StarDomain

Setting Up Cron Jobs in DirectAdmin

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

  1. Log in to your DirectAdmin control panel
  2. Navigate to Advanced Features in the menu
  3. Click Cron Jobs

Creating a New Cron Job

Step 1: Set the Schedule

Each cron job requires five time fields:

FieldAllowed ValuesDescription
Minute0-59Minute of the hour
Hour0-23Hour of the day (24-hour format)
Day of Month1-31Day of the month
Month1-12Month of the year
Day of Week0-6Day 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.php

Tip: 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

ScheduleMinuteHourDayMonthWeekdayDescription
Every 5 minutes*/5****Runs every 5 minutes
Once daily at midnight00***Runs at 12:00 AM
Every Monday at 3 AM03**1Weekly on Monday
First of every month001**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>&1

To send output to a log file instead:

/usr/local/bin/php /home/username/cron.php >> /home/username/cron.log 2>&1

Editing 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 php via 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.

Need help with cron jobs? Contact our support team at {{SUPPORT_EMAIL}} or open a ticket at {{SUPPORT_URL}}.