Nextcloud cron jobs are automated processes that perform regularly recurring tasks such as main­ten­ance, syn­chron­isa­tion, or no­ti­fic­a­tions. If you want to set up a cron job in Nextcloud, you have three different methods available: AJAX, WebCron, and Cron.

Why are cron jobs useful in Nextcloud?

In Nextcloud, cron jobs are crucial for ensuring the ef­fi­ciency and re­li­ab­il­ity of the cloud software. They allow for automated execution of back­ground tasks without requiring user in­ter­ac­tion. These include, for example:

  • Emptying the recycle bin: Nextcloud moves deleted files to a recycle bin. Older versions of files are also stored there to enable recovery. Cron jobs auto­mat­ic­ally delete these items after a set period to save storage space.
  • Regular updates of search indices: When files are uploaded, changed, or deleted, it’s necessary to update Nextcloud’s search indices. Cron jobs handle this task at set intervals so that users can always access up-to-date search results.
  • Email no­ti­fic­a­tions and activity updates: In Nextcloud, cron jobs are also used to inform users about events such as uploads to shared folders or new calendar entries.
  • Back­ground file scanning: To detect changes made outside of the user interface, Nextcloud regularly scans the file system. This task is automated by cron jobs.
  • Main­ten­ance tasks and cleaning: Temporary files, old session data, and no longer needed database entries might impair Nextcloud’s per­form­ance. Cron jobs auto­mat­ic­ally perform cleaning and op­tim­isa­tion tasks to ensure the system’s stability and ef­fi­ciency.
Note

From a technical per­spect­ive, a cron job consists of a script and a command that are executed regularly via the Nextcloud cron.php. The various Nextcloud apps auto­mat­ic­ally register when the cron.php performs the re­spect­ive tasks.

Creating correctly con­figured cron jobs prevents routine tasks from piling up, which can lead to per­form­ance de­grad­a­tion and affect the user ex­per­i­ence. Therefore, it is advisable or even essential to set up cron jobs in Nextcloud.

Managed Nextcloud
Cloud storage that puts you in control
  • Keep your data safe with industry-leading security
  • Save time on updates and main­ten­ance
  • Easily add apps and online office tools

What are the options for setting up cron jobs in Nextcloud?

Nextcloud offers three different methods for setting up and running cron jobs: Cron, AJAX, and WebCron. Each of these options has specific ad­vant­ages and dis­ad­vant­ages and is suitable for different use cases.

AJAX

AJAX is set as the default method in Nextcloud, but it’s con­sidered the most un­re­li­able option. As soon as a user accesses the Nextcloud page, a single back­ground task is executed. The main advantage of the AJAX mechanism is that neither special server con­fig­ur­a­tion nor logging into a third-party service is required. However, the dis­ad­vant­age is that the system reliably completes cron jobs only if the page is visited regularly. Otherwise, data loss or faulty tasks may occur.

Suitable use case: AJAX is re­com­men­ded for small, private user instances.

WebCron

With the WebCron method, the address of the Nextcloud cron.php script is re­gistered with an external service to ensure the regular execution of cron jobs. The basic re­quire­ment for this is that you have the ability to access your server via the internet. However, the web server usually offers only limited resources for executing back­ground tasks.

Suitable use case: WebCron is ideal for small instances with a maximum of five users.

Cron

According to the official Nextcloud doc­u­ment­a­tion, Cron is the preferred method as it enables reliable and efficient execution of back­ground processes. When you set up cron jobs in Nextcloud via Cron, the operating system’s Cron function is used, allowing routine tasks to be executed in­de­pend­ently of web server lim­it­a­tions. However, setting it up requires server access and basic knowledge of con­fig­ur­ing cron jobs.

Suitable use case: Relying on cron in Nextcloud is es­pe­cially re­com­men­ded for larger instances or pro­duct­ive en­vir­on­ments.

Note

Our article on Kuber­netes cron job explains how to automate routine tasks in Kuber­netes.

How to set up cron jobs in Nextcloud (Cron)

To create cron jobs using the Cron service, you must have ad­min­is­trat­ive server rights. The following step-by-step guide demon­strates how to configure cron jobs using the Cron method to execute routine tasks every five minutes:

  1. Access Crontab: Log in to your Nextcloud instance and open the Crontab file by executing the following command: sudo crontab -u www-data -e.
  2. Set up cron job: In Crontab, add the command line */5* ** * php -f /var/www/nextcloud/cron.php. This ensures that cron.php runs every five minutes. Replace the path /var/www/nextcloud/cron.php with the path to your current Nextcloud in­stall­a­tion. Then, save the changes.
  3. Adjust con­fig­ur­a­tion in Nextcloud: Navigate to the basic settings (under ‘Ad­min­is­tra­tion’). In the back­ground jobs section, select ‘Cron’ as the option to ensure the method is used.
Image: Nextcloud: ‘Background jobs’ menu
In the back­ground jobs settings, you will see that Cron is re­com­men­ded for cron jobs in Nextcloud.

Whether the cron job has been added can be verified using the command # crontab -u www-data -l. If everything has worked, the console output should look like this:

[snip]
*/5*    **   * php -f /var/www/nextcloud/cron.php
shell
Tip

Managed Nextcloud Hosting from IONOS provides you with access to a fully main­tained Nextcloud instance without requiring any technical expertise. IONOS handles all server ad­min­is­tra­tion, allowing you to fully focus on your work.

Cron jobs can also be created via systemd

If systemd has been installed on your system, you al­tern­at­ively have the option to manage cron jobs in Nextcloud via this session and main­ten­ance manager. It is used by default in many Linux dis­tri­bu­tions and provides timers for scheduled tasks. This solution offers more detailed control over task schedul­ing and is excellent for server-side en­vir­on­ments.

Dedicated Server
Per­form­ance through in­nov­a­tion
  • En­ter­prise hardware
  • Con­fig­ur­able hardware equipment
  • ISO-certified data centres
Go to Main Menu