# Cron Job

cron is a Linux utility that schedules a command or script on your server to run automatically at a specified time and date. A cron job is the scheduled task itself. Cron jobs can be very useful to automate repetitive tasks.

Every modern application with decent features must have cron job configured in order tasks to be executed in the background.

Concord CRM requires a properly configured cron job, follow the steps explained below to configure cron job for your installation.

For the examples below, make sure to replace `/path/to/concord/` with the path to your installation.

On some shared hosting you may need to specify the full path to the PHP executable (for example, `/usr/local/bin/php82` or `/opt/alt/php82/usr/bin/php` instead of `php`)

Did you know that if you are using our hosted solution, the cron job is automatically configured for you during installation? Learn more

## Setting Up a Cron Job in cPanel

When using cPanel, to ensure that scheduled tasks in Concord CRM run automatically, you need to set up a Cron Job:

1. Log In to cPanel:
   - Access your hosting account's cPanel.
2. Find Cron Job:
   - Use the cPanel search feature and type in "Cron Job" to locate the Cron Jobs section.

3. Add New Cron Job:

   - In the Cron Jobs section, find the option to add a new cron job.

   - Enter the following command in the command field:

         php /path/to/concord/artisan schedule:run >> /dev/null 2>&1

   - Replace `/path/to/concord` with the actual path to your Concord CRM installation.

## Setup Cron Job Via Plesk

- Click Websites & Domains.
- Click the domain/subdomain you installed Concord CRM.
- Click Scheduled Tasks.
- Click Add Task.
- Choose Run a PHP script.
- In the script path enter your Concord CRM installation path and append artisan, for example: /path/to/concord/artisan.
- In the with arguments field enter: schedule:run
- Use PHP version: 8.2
- Cron Style: * * * * *

## Setting Up a Cron Job Via SSH

For server management through SSH, a Cron Job needs to be configured from the command line. It's important to set up the cron job under the user account that handles the web server processes, commonly the www-data user.

1. Open Crontab for the Web Server User:

       sudo crontab -u www-data -e

2. Add the Cron Job: In the crontab file, enter the following line:

       * * * * * php /path/to/concord/artisan schedule:run >> /dev/null 2>&1

3. Replace `/path/to/concord` with the actual path to your Concord CRM installation.

Avoid using the `root` user for configuring the cron job. It should be set under the user account that handles web server processes to ensure proper functionality.

## Verifying Cron Job Configuration

Ensuring that the cron job is correctly set up is crucial for the smooth operation of Concord CRM.

- Access System Info:
  - In your Concord CRM dashboard, go to Settings -> System -> System Info.
- Check Last Cron Run:
  - Look for the Last Cron Run row.
- Confirmation of Proper Setup:
  - If the Last Cron Run value resets every minute, your cron job is configured correctly for your Concord CRM installation.

## Common Cron Job Commands

Below you can find common cron job commands that are confirmed to work for commonly used hosting providers, in most cases the commands are confirmed by our customers and if your hosting provider is listed below, they should work in your environment as well.

The examples below are using path `/path/to/concord/` as an example, make sure to replace this path with the path to your installation.

Is your hosting Concord CRM on a commonly used hosting provider and you can confirm that the cron job command works perfectly fine? Send us the command via our support area so we can add it here and other customers can benefit from it.

### SiteGround

Below you can find a common command that should be used to configure cron job on SiteGround servers.

    /usr/local/php82/bin/php-cli /path/to/concord/artisan schedule:run >> /dev/null 2>&1

### Hostinger

Hostinger does not allow any special characters in the cron job command, in this case, you will need to apply a simple workaround, read more about how to setup cron job on hostinger with special characters.

Find more simple and specific instructions below.

1. Create a `cron.sh` file in the root of your Concord CRM installation directory.

2. In the `cron.sh` file add the following contents:

       #!/bin/sh
       /opt/alt/php82/usr/bin/php /path/to/concord/artisan schedule:run >> /dev/null 2>&1

3. In your Hostinger control panel, navigate to Advanced->Cron Jobs.

4. Choose type custom.

5. In the command to run field enter: `/bin/sh /path/to/concord/cron.sh`

6. Choose the interval as displayed in the image below.

7. Click save.

### Bitnami

If you are using Bitnami, you will need to configure your cron job with the `daemon` user as Bitnami suggest.

Run the following command to open the crontab file:

    sudo crontab -e

At the end of the file add the following command:

    * * * * *  su daemon -s /bin/sh -c "/opt/bitnami/php/bin/php /path/to/concord/artisan schedule:run >> /dev/null 2>&1"