EN · $ USD
Web Hosting and cPanel

How to Set Up a Cron Job in cPanel

7 min read Updated: Sunucu Atlas technical team

In short

To set up a cron job in cPanel, open Cron Jobs under the Advanced section, set the schedule with the minute, hour, day, month and weekday fields, and enter the command using full paths. For PHP scripts, use /usr/local/bin/php followed by the full path to the file; to call a URL, use wget or curl. To stop unwanted notification emails, add >/dev/null 2>&1 to the end of the command.

In this guide
  1. What is a cron job?
  2. Cron schedule syntax
  3. Setting up a cron job in cPanel step by step
  4. Example cron commands
  5. Turning off cron output emails
  6. Common mistakes and how to fix them
  7. How often should each job run?
  8. Testing that a cron job runs
  9. Next step: hosting where cron is easy to use

To set up a cron job in cPanel, open Advanced > Cron Jobs, choose a schedule and enter the command to run using full file paths. The tricky part is not the syntax but the command itself: cron does not see the environment of your terminal, so relative paths and a missing PHP path are the most common errors. In this guide you will find the scheduling rules, ready-to-use example commands and permanent fixes for common errors.

What is a cron job?

Cron is the scheduler service on Linux servers that runs commands automatically at set times. Each line it runs is called a cron job (a scheduled task). Typical uses on websites include:

  • Sending newsletter or notification emails at a set time
  • Cleaning up temporary files, old sessions and logs
  • Updating exchange rates, stock levels or product prices
  • Taking database backups
  • Reliably triggering the Laravel scheduler or WordPress scheduled tasks

Cron schedule syntax

Each cron line consists of five time fields followed by the command:

* * * * *  command
│ │ │ │ │
│ │ │ │ └── Day of week (0-7, 0 and 7 = Sunday)
│ │ │ └──── Month (1-12)
│ │ └────── Day of month (1-31)
│ └──────── Hour (0-23)
└────────── Minute (0-59)

Special characters you can use:

  • * every value (every minute, every hour...)
  • , list: 0,30 minute 0 and minute 30 of every hour
  • - range: 1-5 Monday through Friday
  • / step: */15 every 15 minutes
ScheduleMeaning
*/5 * * * *Every 5 minutes
0 * * * *At the top of every hour
30 3 * * *Every day at 03:30
0 9 * * 1-5Every weekday at 09:00
0 0 1 * *At midnight on the 1st of every month
0 2 * * 0Every Sunday at 02:00

Times follow the server's time zone. If it matters that the task runs at an exact local time (for example, Türkiye time), check the server time with a test job (see the example below).

Setting up a cron job in cPanel step by step

  1. Log in to cPanel and click the Cron Jobs icon in the Advanced section.
  2. In the Cron Email field, you will see the address that notifications are sent to when a job produces output. If you do not want output emails, you can clear this field and update it, or silence the output in the command itself.
  3. Under Add New Cron Job, pick a preset schedule from the Common Settings list (e.g. “Once Per Hour”) or fill in the five fields manually.
  4. In the Command field, enter the command to run using full paths.
  5. Click Add New Cron Job. The job appears in the Current Cron Jobs list below, where you can edit or delete it.

The easiest way to find full paths is the Terminal. Your home directory is usually in the form /home/kullaniciadi (your username). If you are new to the Terminal, see our cPanel SSH and Terminal guide.

Example cron commands

Running a PHP script

/usr/local/bin/php /home/kullaniciadi/public_html/cron/gorev.php >/dev/null 2>&1

On cPanel servers, /usr/local/bin/php calls the command-line PHP. To run with a specific PHP version, use the EasyApache path; you can list the versions installed on the server in the Terminal with ls /opt/cpanel/:

/opt/cpanel/ea-php83/root/usr/bin/php /home/kullaniciadi/public_html/cron/gorev.php

If the script opens files relative to its own folder

Cron runs the command from your home directory. If the script uses relative paths such as include 'config.php';, change into the folder first:

cd /home/kullaniciadi/public_html/cron && /usr/local/bin/php gorev.php >/dev/null 2>&1

Calling a URL (wget or curl)

Some applications expect the cron task to hit a web address. In that case:

wget -q -O /dev/null "https://alanadiniz.com/cron.php?key=GIZLIANAHTAR"

# or
curl -s -o /dev/null "https://alanadiniz.com/cron.php?key=GIZLIANAHTAR"

Remember to put the URL in quotes; if an address containing & is written without quotes, the shell splits the command. When possible, prefer the direct PHP command over a URL: it is not subject to web server timeout limits and cannot be triggered from outside.

Laravel scheduler

In Laravel, a single cron line calls the scheduler every minute, and the task schedules are defined in code:

* * * * * cd /home/kullaniciadi/laravel && /usr/local/bin/php artisan schedule:run >> /dev/null 2>&1

We explain how to keep queue workers running on shared hosting in our Laravel queue and scheduler guide.

WordPress: a real cron instead of WP-Cron

After adding define('DISABLE_WP_CRON', true); to wp-config.php, run this job every 5 or 15 minutes:

cd /home/kullaniciadi/public_html && /usr/local/bin/php wp-cron.php >/dev/null 2>&1

You can find out why this is needed in our guide to disabling WP-Cron.

Daily database backup

An example that takes a compressed backup of the database every night at 03:00. Note that the % signs in the date format are escaped:

0 3 * * * mysqldump --defaults-extra-file=/home/kullaniciadi/.my.cnf kullaniciadi_veritabani | gzip > /home/kullaniciadi/yedekler/db-$(date +\%F).sql.gz

Instead of typing the password on the command line, keep it in a .my.cnf file with 600 permissions:

[client]
user=kullaniciadi_dbuser
password=GUCLU_PAROLA

Keep the backup folder outside public_html and add a second job that deletes old files; otherwise your disk quota will fill up:

30 3 * * * find /home/kullaniciadi/yedekler -name "db-*.sql.gz" -mtime +7 -delete

Managing crontab from the Terminal

If you have SSH access, you can also edit the crontab directly instead of using the cPanel interface. Both methods show the same list:

crontab -l    # lists current jobs
crontab -e    # opens jobs in an editor

Turning off cron output emails

If a job prints anything to the screen, cron sends that output to the Cron Email address. A job that runs every minute can flood your inbox and use up your account's hourly email sending limit. You have three options:

  • Silence everything: Add >/dev/null 2>&1 to the end of the command. The first part redirects normal output, and 2>&1 sends error output to the same place.
  • Get errors only: Use just >/dev/null; normal output is discarded, and you get an email only if there is an error.
  • Write to a log file: This is the most useful option while debugging.
/usr/local/bin/php /home/kullaniciadi/public_html/cron/gorev.php >> /home/kullaniciadi/logs/cron-gorev.log 2>&1

To keep the log file from growing forever, remove this redirect when you are done or clear the file regularly.

Common mistakes and how to fix them

  • Using relative paths: php gorev.php does not work in cron because the working directory is your home directory. Always use full paths or cd into the folder first.
  • Wrong PHP: Your site's PHP version and the command-line PHP may differ. If the script needs newer version features, specify the /opt/cpanel/ea-phpXX/ path explicitly.
  • Percent sign: In a crontab line, % means a new line. In expressions like date +%Y-%m-%d, write every % as \%.
  • Limited environment variables: Cron does not load the PATH and variables from your terminal. Use full paths for commands like composer and node too; you can find the path with which node.
  • Overlapping runs: If a long-running job has not finished before the next trigger, two copies run at the same time. Prevent this with flock:
    */5 * * * * flock -n /home/kullaniciadi/gorev.lock /usr/local/bin/php /home/kullaniciadi/public_html/cron/gorev.php >/dev/null 2>&1
  • Windows line endings: CRLF line endings in .sh scripts written on Windows and uploaded cause a “bad interpreter” error. Save the file with LF line endings.
  • Running too often: Running a heavy job every minute strains your account's CPU limit and slows down the site. Choose the interval based on what you actually need.

How often should each job run?

When choosing an interval, ask “how much delay is acceptable?” rather than “how often can it run?” For work users are waiting on, such as queues and sending email, 1-5 minutes is usually enough; for cache warming and stock syncing, 15-60 minutes; and for backups and log cleanup, once a day. Scheduling heavy jobs for the night hours when visitor traffic is lowest means a smoother site on the same plan.

Testing that a cron job runs

  1. Run the command manually in the Terminal first. A command that does not work in the Terminal will not work in cron either.
  2. Temporarily add a test job that runs every minute:
    * * * * * date >> /home/kullaniciadi/cron-test.txt
  3. A few minutes later, open the file in File Manager. If lines are being added, cron is working; the time written also shows the server's time zone.
  4. When you are done testing, delete the job and the file.

Next step: hosting where cron is easy to use

For simple sites, managing cron takes just minutes in cPanel's Cron Jobs screen; our cPanel web hosting plans run scheduled tasks like these comfortably with LiteSpeed web server and NVMe storage. If your project uses Laravel, Composer or Git, take a look at our Laravel hosting plans, which offer Terminal / SSH access, PHP version selection and a Node.js and Python app manager; if you are starting with a single project, the SA-DEV-1 developer plan lets you manage the scheduler and deployments from one panel. If your cron command is not working on Sunucu Atlas, you can open a support ticket for help.

Frequently asked questions

How often can a cron job run in cPanel?

Cron syntax supports one minute as the smallest unit, so a job can run at most once a minute. Because running heavy jobs every minute strains the account's CPU limit, it is better to choose intervals such as 5 or 15 minutes based on what you actually need.

How do I stop emails from cron jobs?

Add >/dev/null 2>&1 to the end of the command, or clear the Cron Email field on the Cron Jobs screen. If you want to see errors, redirect the output to a log file.

Why does my command work in the Terminal but not in cron?

Cron runs with a different working directory and limited environment variables. Write out full paths for all files and programs, and if the script uses relative paths, add cd /full/path && to the start of the command.

Which time zone does a cron job use?

It runs on the server's system time zone. To be sure, add a temporary job that writes the output of the date command to a file and check the time in the output.

Should I set up cron with a URL or a PHP command?

Use the direct PHP command whenever possible. It does not hit web server timeouts and the task cannot be triggered from outside; use the URL method only if your software requires it.

For this guide

Recommended plans

Want to manage scheduled tasks easily from cPanel, and get Terminal and SSH access for projects that use the Laravel scheduler or Composer? Our web hosting and Laravel hosting plans are built for exactly that.

SA-CP-1

cPanel
Recommended

20 GB NVMe disk

$0.39/mo

+VAT

  • Memory1 GB
  • LocationIstanbul
  • 1 Hosted Domains
  • 50 GB Traffic
  • 5 Email Account Limit
  • 2 Databases

SA-CP-2

cPanel

40 GB NVMe disk

$0.69/mo

+VAT

  • Processor2 cores
  • Memory2 GB
  • LocationIstanbul
  • 1 Hosted Domains
  • 100 GB Traffic
  • 10 Email Account Limit
  • 5 Databases

SA-CP-3

cPanel

60 GB NVMe disk

$0.98/mo

+VAT

  • Processor3 cores
  • Memory3 GB
  • LocationIstanbul
  • 1 Hosted Domains
  • 200 GB Traffic
  • 25 Email Account Limit
  • 10 Databases

Web Hosting — all plans Laravel Hosting — tüm paketler

Need help with setup?

Send questions about your service in a support ticket, and our technical team will walk you through it step by step.