Disable scheduled tasks

NOTE: We are in the process of modifying the file structure and configuration for many Bitnami stacks. On account of these changes, the file paths stated in this guide may change depending on whether your Bitnami stack uses native Linux system packages (Approach A), or if it is a self-contained installation (Approach B). To identify your Bitnami installation type and what approach to follow, run the command below:

 $ test ! -f "/opt/bitnami/common/bin/openssl" && echo "Approach A: Using system packages." || echo "Approach B: Self-contained installation."

The output of the command indicates which approach (A or B) is used by the installation, and will allow you to identify the paths, configuration and commands to use in this guide. Refer to the FAQ for more information on these changes.

The wp-cron.php script will run once a user visits your site. If you get a lot of traffic, this could be a problem. This cron task is really necessary when you make updates in the blog. You can move this cron script to a system cron task to help lower resource usage on the server.

Disable the wp-cron.php script in the WordPress wp-config.php configuration file. The location is important - add the line below just before the database settings:

NOTE: Depending on your installation type, the WordPress wp-config.php configuration file can be found in the following locations:

  • Approach A (Bitnami installations using system packages): /opt/bitnami/wordpress/wp-config.php

  • Approach B (Self-contained Bitnami installations): /opt/bitnami/apps/wordpress/htdocs/wp-config.php

define('DISABLE_WP_CRON', true);

Then, add the cron task to the system. There are two options:

  • Create a cron task for each WordPress site and set a different execution interval for each. For example, the cron tasks shown below will run every 15 minutes and 30 minutes respectively. This is fine if there aren’t a large number of sites.

      $ sudo crontab -e
      */15 * * * * wget -q -O - "`date +\%s`" > /dev/null 2>&1
      */30 * * * * wget -q -O - "`date +\%s`" > /dev/null 2>&1
  • Create a unique cron task for all the domains and share the execution interval. This option is better if you have a large number of WordPress sites and all of them share the same tasks.

    • Create the following script as wp-cron-multisite.php at the WordPress installation directory:

      NOTE: Depending on your installation type, the wp-cron-multisite.php script should be in the following locations:

      • Approach A (Bitnami installations using system packages): /opt/bitnami/wordpress/wp-cron-multisite.php

      • Approach B (Self-contained Bitnami installations): /opt/bitnami/apps/wordpress/htdocs/wp-cron-multisite.php

        require(__DIR__ . '/wp-load.php');
        global $wpdb;
        $sql = $wpdb->prepare("SELECT domain, path FROM $wpdb->blogs WHERE archived='0' AND deleted ='0' LIMIT 0,300", '');
        $blogs = $wpdb->get_results($sql);
        foreach($blogs as $blog) {
            $command = "http://" . $blog->domain . ($blog->path ? $blog->path : '/') . 'wp-cron.php';
            $ch = curl_init($command);
            $rc = curl_setopt($ch, CURLOPT_RETURNTRANSFER, FALSE);
            $rc = curl_exec($ch);
    • Set the correct permissions:

        $ sudo chown bitnami:daemon wp-cron-multisite.php
    • Add the task to the system crontab. For example, this cron task will run the script for each domain every hour. Add it using the following command:

        $ sudo crontab -e
        0 * * * * wget -q -O - "`date +\%s`" > /dev/null 2>&1

For more information, refer to this blog post.

Last modification June 16, 2021