Ultimate guide to Mautic cronjobs

I created this guide for self-hosted Mautic users to understand, troubleshoot and optimise their crontab and time their Mautic cronjobs the proper way. It will help you to figure out why Mautic emails are not sent out, why campaign steps are stuck, and why segments or email sending are not working.

Why you need cronjobs?

Cron is a background process on your server, that schedules tasks to run at certain times. In case of Mautic, they make sure, that your segments are recalculated every 5 minutes, your campaigns are updated based on the freshly recalculated segments and your campaign actions are triggered based on the freshly calculated campaigns. In some cases you might even use separate scheduled task to send emails, but I’ll cover that later.

Finding your crontab

Crontab is a list of commands. When, what needs to be done. Depending on the system you use, you can change it’s setting at different ways. In this guide, I’ll try to cover as many different systems as possible.

Cpanel

There is a separate menu in Cpanel for the crontab. This is how it looks:

By clicking on the Cronjobs, you can edit them. You just need to fill out this form, and your crontab is online:

There are 2 ways to define the cronjob schedule.

  1. Choose from the common settings.
    This is for beginners, and you are clearly not one.
  2. Enter the proper timing data into the table.
    In this example we will choose to run the crontab every 15 min from the 1st min of the hour until the 46th minute. In other words 4x an hour. And that is every hour, every day, every month, every weekday.
    We will do this, and our result will look like this:

This setting will generate something like this:

Which is actually great, but now we have to understand the command itself.

If you have ssh access

In case of an SSH access your task is easier. Simply enter crontab -e and edit the cron file.

The command structure

php /var/www/html/mautic/bin/console mautic:segment:update --batch-limit=900

php : this part of the command is used to execute a php command. Most likely you don’t have to change it.
/var/www/html/mautic : it’s your path to your Mautic installation. In the next section we’ll discuss how to find it.
/app/console (or /bin/console in case of Mautic 3.+) : This is your path within your Mautic folder. Shouldn’t be changed.
mautic:segment:update : Describes the command you perform. Updates segments in this case.
–batch-limit=900 : This switch limits the batch size. Optional usage.

If you form a command from these parts above, you’ll get your Mautic command.

Before you read further: Your chance to get Mautic Tips and Secrets in Your inbox!

In this weekly email you’ll recieve never published guides, ready to deploy code samples, premium templates!

Find your Mautic path: Cpanel

How can you find out the Mautic path? Not that complicated.

  1. Open your file manager in Cpanel. On the right upper corner you’ll see your path:

2. Now navigate into your Mautic folder by clicking to the folder names. Probably it’s in your public_html and inside that in a mautic folder. At least it is in this example:

In this particular case our path would look like:

/home/stender/public_html/mautic

And that would make our full command look like:

php /home/stender/public_html/mautic/bin/console mautic:segment:update --batch-limit=900

Find your path: SSH

Log in into your instance. If you installed it yourself, probably it is no problem to find the path. But there are some hints:

  1. check your apache public_html root:
cd /var/www/html
ls

if you see the Mautic files here, for example (readme.md and upgrade.php) than your path will be:

/var/www/html

Maybe you see a ‘Mautic’ folder here. Than your path will be:

/var/www/html/mautic

That would make your full command:

php /var/www/html/mautic/bin/console mautic:segment:update --batch-limit=900

How do I know if I have the right path? Well, just run the command above in ssh and see if you get an error.

Learn the timings

crontab-syntax

As you see the example above, the timing is kinda part of the command. You need to define the 5 time slots to generate the right timing.

  1. minute of the hour
  2. hour of the day
  3. day of the month
  4. month of the year
  5. weekdays

For example:

* * * * *  = every minute, every hour, every day, every month, every weekday
10 * * * * = :10 at every hour every day, every week, every month, every weekday
* 1 * * *  = every minute, one o'clock, every day, every month, every weekday

So I hope you get the point. If not, you should really learn crontab for beginners.

What to run and what to run

In order to run Mautic you’ll need 3 basic commands. Please don’t run them at the same time, better like 5 minutes apart.
In this case your cron structure should look like this:

 0,15,30,45 php /var/www/html/mautic/bin/console mautic:segment:update --batch-limit=900
 5,20,35,50 php /var/www/html/mautic/bin/console mautic:campaigns:update --batch-limit=100
10,25,40,55 php /var/www/html/mautic/bin/console mautic:campaigns:trigger

If you turned on queue for email sending in Mautic Settings-Email, you’ll need to add the proper cronjob to send out the emails from your queue folder. You can use the following command for that:

13,28,43,58 php /var/www/html/mautic/bin/console mautic:emails:send

This is not everything. You can use future publishing of an email, in the individual email view here:

This date will determine when the emails will be pulled into the queue. In order to get it work it, we need to set one more crontab:

12,27,42,57 php /var/www/html/mautic/bin/console mautic:broadcast:send

These are the basic cron job settings for Mautic. Want to read more? Check out this knowledgebase article:

Looking for timing emails efficiently with cronjobs?

Check out the knowledgebase afrticle below:

Check the knowledge base!

Learn more about advanced Cron job setup!

Get Mautic Tips and Secrets in Your inbox!

In this weekly email you'll recieve never published guides, ready to deploy code samples, premium templates!

Learn Mautic Cronjobs!

I was presenting advanced cronjobs techniques for Mautic at the 2020 Lagos Meetup.

In this video you can learn how to run your cronjobs better, more often, send more emails, and have a stable system, that runs like a swiss watch.

Cronjob finetuning

We did some cronjob fine tuning during the Lagos Mautic Meetup in 2020 October!

Whi