Skip to main content

Cron jobs let you automate recurring tasks on your hosting account, from running PHP scripts and generating reports to clearing temporary files and carrying out scheduled maintenance. Instead of remembering to run a task manually, you define when it should run and the server executes it at the specified time.

This guide explains how to create cron jobs in cPanel and through SSH, how to read the five-field cron schedule, and how to run PHP and WordPress tasks reliably. It also covers common problems such as incorrect file paths, permissions, time zones, missing environment variables and overlapping jobs.

What is a cron job?

A cron job is a scheduled command that runs automatically on a Unix-like server. The cron service checks a schedule and launches the command when its date and time fields match. Cron is commonly used for backups, data imports, report generation, maintenance scripts and other repeatable server tasks.

A cron job normally runs under the account that owns the crontab entry. This matters because that account determines which files, folders and commands the task can access. Only schedule commands you understand and have permission to run.

Understand cron schedule syntax

A standard crontab entry contains five time fields followed by the command to execute:

* * * * * command-to-run
| | | | |
| | | | +--- Day of the week (0-7, Sunday is 0 or 7)
| | | +----- Month (1-12)
| | +------- Day of the month (1-31)
| +--------- Hour (0-23)
+----------- Minute (0-59)

Each field accepts numbers and scheduling operators. An asterisk means every permitted value, a comma separates specific values, a hyphen defines a range, and a slash sets an interval. For example, */15 in the minute field means every 15 minutes.

ScheduleMeaning
0 0 * * *Every day at midnight
*/15 * * * *Every 15 minutes
0 9 * * 1Every Monday at 09:00
30 2 * * *Every day at 02:30
0 0 1 * *At midnight on the first day of each month
0 8,16 * * 1-5At 08:00 and 16:00, Monday to Friday

Be careful when combining the day-of-month and day-of-week fields. On common cron implementations, when both are restricted (not set to an asterisk), a job can run when either field matches. Check your server’s cron documentation if a schedule depends on this distinction.

How to set up a cron job in cPanel

cPanel provides a graphical Cron Jobs interface, which is convenient if you do not want to edit a crontab over SSH. The exact layout can vary slightly by cPanel version and hosting provider.

1. Sign in to cPanel

Open cPanel from your hosting client area. Some providers also allow access through a URL such as https://yourdomain.com:2083, although the client-area link is usually the safest route.

2. Open Cron Jobs

Find the Advanced section and select Cron Jobs. If you cannot see the option, your hosting plan or account permissions may not include cron management. Contact your hosting provider to confirm availability.

3. Configure email notifications

cPanel may offer an email address for cron output. When a command writes output, cPanel can send that output to the configured address. This is useful while testing, but a frequent task can generate a large volume of messages. You can redirect output to a log file instead, or suppress output once you are confident the job is working.

4. Choose the schedule

Choose a common interval from the dropdowns or enter the minute, hour, day, month and weekday values yourself. For example, to run a task every day at 02:30, use 30, 2, *, * and * in the five fields.

5. Enter the full command

In the command field, enter the interpreter and the absolute path to the script. A PHP example might look like this:

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

The PHP executable path differs between servers. Common locations include /usr/bin/php and /usr/local/bin/php, but do not assume either is correct. Check your hosting documentation, cPanel’s PHP information or ask your provider for the CLI PHP path and version.

6. Save and test the job

Select the option to add the cron job, then confirm that it appears in the current jobs list with the schedule and command you intended. If possible, choose a schedule a few minutes ahead while testing, then inspect its output or log. Once confirmed, change it to the intended production schedule.

Need a cPanel-based hosting environment? DaManager Shared Hosting includes a cPanel-powered hosting environment for managing common website and account tasks.

DaManager Shared Hosting
DaManager Shared Hosting

Explore cPanel-powered shared hosting for websites and everyday hosting management.

View Shared Hosting plans

How to create cron jobs using SSH

If your hosting plan provides SSH access, you can manage cron jobs from the command line. This method is common on VPS and dedicated servers, and may also be available on shared hosting accounts.

1. Connect to your hosting account

Connect using your SSH client and the host, port and username supplied by your provider. If you need help connecting, see our guide on how to use SSH to manage your hosting server.

2. Open your user’s crontab

crontab -e

This opens the crontab for the current user in the configured text editor. Add one scheduled command per line. Save and exit the editor to install the updated crontab. Use crontab -l to list the current user’s entries.

3. Add a scheduled PHP script

30 2 * * * /usr/bin/php /home/username/scripts/report.php

This example runs a PHP report script every day at 02:30. Replace the PHP executable and script paths with the actual paths on your server. You can check the PHP CLI version with php -v and, where permitted, locate the executable with command -v php.

4. Check and remove entries carefully

crontab -l
crontab -e

Review the list before editing. Avoid replacing the entire crontab with a partial file unless you have backed up the existing entries. A useful precaution is to save a copy of the current schedule before making significant changes.

How to run PHP scripts reliably

Scripts launched by cron do not necessarily inherit the same working directory, shell configuration or environment variables as an interactive SSH session. Use absolute paths for the PHP executable, script, input files and output files. If the script relies on environment variables, define the required values explicitly in the command or in a protected configuration file.

For example, redirect standard output and errors to a log file while testing:

30 2 * * * /usr/bin/php /home/username/scripts/report.php >> /home/username/logs/report.log 2>&1

Make sure the account running the cron job can write to the log directory. Protect log files if they contain personal data, credentials or other sensitive information, and rotate or clear them periodically so they do not consume all available disk space.

Using cron jobs with WordPress

WordPress includes a scheduling system called WP-Cron. It is used for tasks such as publishing scheduled posts, checking for updates and running scheduled plugin actions. Unlike a system cron service, WP-Cron is normally triggered by site requests. If a site receives little traffic, a scheduled task may run later than expected because no request has triggered the scheduler.

For sites that need more predictable scheduling, an administrator may configure the server’s cron service to call WordPress’s wp-cron.php endpoint at a regular interval. This should be planned carefully: after confirming the system task is working, WordPress’s page-load trigger can be disabled by defining the following constant in wp-config.php:

define('DISABLE_WP_CRON', true);

Then configure a system cron job to request the site’s cron endpoint. For example, using a command-line HTTP client:

*/5 * * * * curl -fsS https://example.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1

Replace the domain with your site’s canonical HTTPS address and confirm that the command-line HTTP client is available. Some hosting environments recommend a PHP-based method or a different command. Do not disable the normal WP-Cron trigger until the replacement schedule is in place and tested, or scheduled WordPress tasks may stop running.

Administrators with WP-CLI access can inspect scheduled events using wp cron event list and test the cron system with wp cron test. These commands help identify overdue events and configuration problems.

Common cron job problems and how to fix them

The cron job does not run

Check that the entry was saved, the schedule is valid and the hosting plan permits cron execution. Confirm that the cron service is available and that the command works when run manually under the same account. On managed or shared hosting, ask the provider whether execution limits or account restrictions apply.

The command works in SSH but fails in cron

This often happens because cron uses a limited environment. Specify the full path to executables and files, set any required environment variables, and set the working directory explicitly if the script expects one. Do not rely on aliases or shell startup files that may not be loaded for scheduled commands.

PHP version or executable path is incorrect

The PHP version used by the command line can differ from the version assigned to the website. Confirm the correct CLI binary with your host and test it using /path/to/php -v. If the script requires a particular PHP version or extension, check that the CLI configuration provides it.

Permission denied errors

Check that the cron user’s account has permission to execute the script and read its dependencies, and write to any output or log directories. Avoid making files world-writable as a quick fix. Correct ownership and the minimum permissions needed are safer.

The job runs at the wrong time

Check the server’s time zone and the time zone used by the hosting control panel. Cron commonly uses the server’s configured time zone, which may differ from your local time or the time zone configured in WordPress. Confirm the actual server time with your provider before changing the schedule.

The job runs more than once or overlaps

If a task takes longer than its interval, another instance may start before the previous one finishes. This can duplicate work or put unnecessary load on the server. Reduce the frequency, optimise the script or use a locking mechanism appropriate for your environment. Also check that the same task has not been configured in both cPanel and a user’s crontab.

There is no useful output to diagnose the failure

Temporarily redirect standard output and errors to a protected log file. Review the application’s own logs as well as hosting error logs. Our guides to using error logs in cPanel and monitoring server resources in cPanel can help you investigate related problems.

Best practices for managing cron jobs

  • Test each command manually before scheduling it.
  • Use absolute paths for executables, scripts, files and logs.
  • Run jobs with an account that has only the permissions required.
  • Schedule resource-intensive tasks outside your website’s busiest periods where practical.
  • Log useful output while testing, then manage log size and retention.
  • Prevent duplicate and overlapping runs where a task is not safe to run concurrently.
  • Review cron entries periodically and remove obsolete schedules.
  • Keep scripts, credentials and configuration files protected.
  • Monitor the server if scheduled tasks consume significant CPU, memory or disk I/O.

Frequently asked questions

Do I need SSH to create a cron job?

No. If your hosting account provides cPanel Cron Jobs, you can create and manage scheduled tasks through the control panel. SSH is an alternative for users who prefer command-line administration or need more control.

Can I run a PHP script with a cron job?

Yes. Use the correct PHP command-line executable followed by the absolute path to your PHP script. Confirm the CLI PHP version and permissions with your hosting provider if the script fails.

How often can a cron job run?

Standard cron syntax can schedule jobs as frequently as once per minute. Your hosting provider may impose minimum intervals, execution time limits or resource restrictions, so check your plan before scheduling frequent tasks.

What is the difference between cron and WP-Cron?

System cron is a server-level scheduler that runs according to the server’s clock. WP-Cron is WordPress’s application-level scheduler and is normally triggered by site traffic. A system cron can be used to trigger WP-Cron more predictably, but it must be configured and tested correctly.

Why should I use absolute paths in cron commands?

Cron jobs often run with a smaller environment and a different working directory from an interactive shell. Absolute paths remove ambiguity about which executable and files the command should use.

Further reading and official documentation

Setting up cron jobs is a straightforward way to automate routine work on a hosting account, provided that each command is tested, scheduled sensibly and monitored. Start with a simple task, confirm that it runs as expected, and then add more automation as your requirements grow.