Choose a plan

Cron jobs: scheduled tasks in Enhance

How to schedule a PHP script or a web address to run automatically from Enhance, with WordPress examples and fixes for when it doesn't run.

  • Updated
guide · advanced
Steps
16
Reading time
5min
Sections
4
Start the guide

A cron job is a command the server runs on its own, at times you set: every 15 minutes, every night or once a week. Online stores, newsletter plugins, stock syncs and WordPress (for scheduled posts) all use it. Cron jobs are included in every web hosting plan, along with the file manager and encrypted FTP.

What you'll achieve

  • add, edit and delete a cron job in Enhance;
  • run a PHP script with the same PHP version as the website;
  • keep the output of each run in a file, so you can see whether the script throws errors.

Before you start

  • Our plans don't include SSH access, but cron jobs work. The server runs them in the website's isolated environment, with the PHP version chosen for the website.
  • Write paths starting from $HOME, your website's directory. The main website is in $HOME/public_html, so a script there is written as $HOME/public_html/cron.php. The server replaces $HOME with the full path automatically.
  • You can see the website's PHP version (8.2, 8.3 or 8.4) in “Developer tools”, under “PHP” (see PHP version and PHP settings).
  • Times are Romanian time (EET/EEST), because the server is set to the Bucharest time zone.
  • The names in this guide are the ones from the English Enhance interface. If Enhance opens in another language, you can switch it to English from the top right: your photo or initials » “My account” » “Language”.

The steps

  1. Log in to Enhance at https://server.nbt-host.com. In the left-hand menu, click “Websites”, then your website.
  2. Open the “Developer tools” tab. If you don't see it in the row of tabs, it's in the “Advanced” menu, at the end of the row.
  3. Go to “Cron jobs” and click “Add cron job”. If you don't have any yet, the button is called “Add”.
  4. Under “Cron type”, choose:
    • “Run command”, to run a command or a script. You enter the command under “Command”;
    • “Request URL”, to open a web address. You enter the address under “Request URL”, starting with http:// or https://. Enhance calls it on its own, without keeping any output.
  5. Under “Interval”, choose how often it runs: “Every minute”, “Every 15 minutes”, “Every hour”, “Every day” (at midnight), “Every week” (Monday, at midnight) or “Every month” (on the 1st, at midnight). For another time, choose “Custom” and fill in “Minute”, “Hour”, “Day of month”, “Month” and “Weekday” below. Each has a list of ready-made options and a box where you type the value yourself. For 3:00 a.m., for example, you enter 0 under “Minute” and 3 under “Hour”.
  6. Click “Add”. The cron job appears in the list, with its command and interval.
  7. To change it, open the row menu, click “Edit”, make your changes and click “Save”. To delete it, choose “Delete” from the same menu and confirm.

Command examples

In the examples, replace the path and the address with your real ones.

A PHP script, run with the “Run command” type:

php $HOME/public_html/cron.php

The php command starts the same PHP version as the website, so you don't write the version number anywhere. If you change the website's version, the cron job uses the new one.

A web address, for plugins that give you a cron link: choose the “Request URL” type and paste the link, for example https://domeniul-tau.ro/cale/catre/cron.

WordPress, with a real cron instead of the one triggered by visitors:

First look at the “Cron jobs” list: if there is already a row with wp-cron.php, the website has a real cron and you don't add another one. Otherwise:

  1. Open wp-config.php from the “Files” tab and, above the line starting with /* That's all, stop editing!, add:
    define( 'DISABLE_WP_CRON', true );
  2. Add a cron job of the “Request URL” type, with the “Every 15 minutes” interval and the address:
    https://domeniul-tau.ro/wp-cron.php?doing_wp_cron

If the website has many scheduled tasks, such as a store with lots of orders, choose “Custom” and enter */10 under “Minute”: it runs once every 10 minutes.

Output of the runs

Enhance has no setting for emailing the output of each run. To see what a command does, keep its output in a file: add >> $HOME/cron.log 2>&1 at the end of the command. The cron.log file appears in the “Files” tab, next to public_html. Empty it from time to time, because otherwise it grows and takes up space.

When the script works properly, replace the ending with > /dev/null 2>&1: the output is no longer kept anywhere.

A few good rules

  • Run the task only as often as you need. For most websites, once every 15 minutes is enough. Running every minute loads the server for nothing.
  • Leave enough time between runs, so one finishes before the next one starts.
  • Write full paths, starting from $HOME/..., not relative paths.
  • Don't use the % character in the command: it has a special meaning for cron. If you need it, write \%.
  • Be very careful with commands that delete files (rm): with a wrong path you can delete the whole website.
  • Leave the “Allow editing of cron from website container” setting off. If you turn it on, scripts on the website can add cron jobs by themselves — and that's exactly what malware for WordPress does.

If something doesn't work

  1. The cron job doesn't run at all. Check the time (the server uses Romanian time) and the path, which must start with $HOME/. Temporarily add >> $HOME/cron.log 2>&1 at the end of the command and open cron.log after the next run: the error shows up there.
  2. cron.log says “Permission denied”. You probably wrote only the script's path. Put the program that runs it in front, for example php $HOME/public_html/cron.php.
  3. The script works from the browser, but not from cron. Some scripts look for files starting from the folder they are in. Go into their folder first: cd $HOME/public_html && php cron.php.
  4. cron.log grows too large. Empty it or replace the end of the command with > /dev/null 2>&1.
  5. The website is slow at certain times. Probably two heavy tasks start at the same time or run too often. Schedule them at different times, at night, and run them less often.
Support

Stuck? We'll do it together.

Tell us which step isn't working and, if you can, send a screenshot. We reply during business hours.

Phone and WhatsApp+40 775 396 021
HoursMonday–Friday, 9:00–18:00 Romanian time (EET/EEST)

Never send us your password on WhatsApp or by email. What information helps us solve it on the first try: how to ask for help.