# Cron Job

> Set up the scheduler cron job that runs email sync, Autopilot scans, reminders and digests in a self-hosted Advanzo CRM.

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 are very useful for automating repetitive tasks.

Most modern applications need a configured cron job so that tasks can be
 executed in the background.

**Advanzo CRM requires a properly configured cron job**. Follow the
 steps below to configure the cron job for your installation.

> **Warning:** For the examples below, make sure to replace
>  `/path/to/advanzo/` 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/php81` or `/opt/alt/php81/usr/bin/php`
>  instead of `php`).

> **Info:** On the hosted version at [advanzo.app](https://advanzo.app) this is already configured. This page applies to Enterprise installations on your own infrastructure.

## Setting Up a
 Cron Job in cPanel

If you use cPanel, set up a cron job so that the scheduled tasks in Advanzo
 CRM run automatically:

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:

      ```bash
      php /path/to/advanzo/artisan schedule:run >> /dev/null 2>&1
      ```
    - Replace `/path/to/advanzo` with the actual path to your
       Advanzo CRM installation.

## Setting Up a Cron Job
 in Plesk

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

## Setting Up a Cron
 Job Via SSH

If you manage your server through SSH, configure the cron job from the
 command line. Set up the cron job under the user account that
 runs the web server processes, commonly the **www-data** user.

1. **Open Crontab for the Web Server User**:

  ```bash
  sudo crontab -u www-data -e
  ```
2. **Add the Cron Job**: In the crontab file, enter the following
   line:

  ```bash
  * * * * * php /path/to/advanzo/artisan schedule:run >> /dev/null 2>&1
  ```
3. Replace `/path/to/advanzo` with the actual path to your Advanzo
   CRM installation.

> **Warning:** Do not use the `root` user to
>  configure the cron job. Set it up under the user account that runs the
>  web server processes, so that it works properly.

## Verifying Cron Job
 Configuration

Advanzo CRM only works reliably if the cron job is set up correctly. To
 check it:

- **Access System Info**:

    - In your Advanzo 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 is updated every minute,
       your cron job is configured correctly for your Advanzo CRM
       installation.

## Common Cron Job
 Commands

Below are cron job commands that are confirmed to work with commonly used
 hosting providers. In most cases our customers confirmed them, so if your
 hosting provider is listed below, the command should work in your
 environment as well.

> **Warning:** The examples below use the path `/path/to/advanzo/`
>  as an example. Make sure to replace it with the path to your
>  installation.

> **Info:** Do you host Advanzo CRM with a commonly used
>  hosting provider, and can you confirm that the cron job command works? Send us
>  the command via our support area so that we can add it here and other
>  customers can benefit from it.

### SiteGround

Use the following command to configure the cron job on
 SiteGround servers.

```bash
/usr/local/php81/bin/php-cli /path/to/advanzo/artisan schedule:run >> /dev/null 2>&1
```

### Hostinger

Hostinger does not allow any special characters in the cron job command, so
 you need to apply a simple workaround. Read more about [how
 to set up a cron job with special characters at Hostinger](https://support.hostinger.com/en/articles/5646919-how-to-set-up-a-cron-job-with-special-characters-at-hostinger).

The specific steps are simple:

1. Create a `cron.sh` file in the root of your Advanzo CRM
   installation directory.
2. Add the following contents to the `cron.sh` file:

  ```bash
  #!/bin/sh /opt/alt/php81/usr/bin/php /path/to/advanzo/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/advanzo/cron.sh`
6. Set the interval so the job runs every minute: set
   **minute(s)**, **hour(s)**, **day(s)**,
   **month(s)** and **weekDay(s)** all to
   **Every (*)**.

1. Click save.

### Bitnami

If you are using Bitnami, configure your cron job with the
 `daemon` user, as Bitnami [suggests](https://docs.bitnami.com/aws/apps/seopanel/configuration/configure-scheduler/).

Run the following command to open the crontab file:

```bash
sudo crontab -e
```

Add the following command at the end of the file:

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