Cronjob setup for Mautic

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.

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:

Whi

Tags:

13 Comment

  • Marcel

    says:

    I watched the cronjob fine tuning video and have some questions.
    You put your shell script to combine commands in
    /usr/local/bin/mauticcron.sh

    does it matter where you put it? E.g. can I put it in
    /pathtomautic/scripts/mauticcron.sh

    And you mention you check the spool folder at
    /pathtomautic/bin/spool/default

    mine is located in (v3.2.4)
    /pathtomautic/var/spool

    Is that a Mautic version difference?

    Reply
    • jos0405

      says:

      Hello Marcel!
      Yes, this article was written for 2.16, but you are right: 3+ is using the path you mentioned.
      Thanks for noticing, I’ll update the blogpost.
      YOu can put the shell script where ever it runs. it’s up to you 🙂
      Joey

      Reply
  • Rommel

    says:

    Hi, I have a shared domain or host, My path to mautic is like /home/maindomain/local_host/sharedomain/mautic/ — crons seem doesn’t work. I don’t even know my PHP path and seems I dont have ssh access. I have previously installing crons and mautic on different domains but not on a shared domain. Will that even matter?

    here’s my cron looks like:
    php /home/maindomain/public_html/DOMAINIWORKWITH/mautic/bin/console mautic:segments:update

    Reply
  • Marina

    says:

    I have not been able to configure the campaigns to automate the sending of emails with Mautic, the contacts do enter the campaigns but the events remain pending. If I send a test email if it reaches me and it registers correctly in amazonSES, but the campaigns do nothing 😂

    Not even if I just want to add a label in the campaign, it stays “pending”.
    Have an idea how to solve it?
    Thankyou!

    Reply
    • jos0405

      says:

      Hello Marina!
      you def. have cronjob issue. Try to run the cronjob in the command line, and if you get an error, that can help you further.
      You’ll need to know where on the server your Mautic is installed. Usually it’s /var/www/html if you are using apache. Maybe it’s /var/www/html/mautic.
      In this case just run
      php /var/www/html/mautic/console mautic:campaigns:update
      What answer you get?

      Reply
  • PHB

    says:

    Hello Jozsef, thank you for your explanation. As a rookie, I am not sure on how to proceed with the right format for the cronjob on acronatab ?

    I would have something like this:

    0,15,30,45 php web/vhosts/mautic/htdocs/bin/console mautic:segments:update
    5,20,35,50 php web/vhosts/mautic/htdocs/bin/console mautic:campaigns:update
    10,25,40,55 php web/vhosts/mautic/htdocs/bin/console mautic:campaigns:trigger
    13,28,43,58 php web/vhosts/mautic/htdocs/bin/console mautic:emails:send
    12,27,42,57 php web/vhosts/mautic/htdocs/bin/console mautic:broadcast:send
    * * * * php web/vhosts/mautic/htdocs/bin/console mautic:email:fetch
    * * * * php web/vhosts/mautic/htdocs/bin/console mautic:social:monitoring
    * * * * php web/vhosts/mautic/htdocs/bin/console mautic:import
    * * * * php web/vhosts/mautic/htdocs/bin/console mautic:iplookup:download
    * * * * php web/vhosts/mautic/htdocs/bin/console mautic:donotsell:download
    * * * * php web/vhosts/mautic/htdocs/bin/console mautic:max-mind:purge

    Reply
      • PHB

        says:

        Hello,

        Actually I did use Anacrontab so the format is : (this could be useful as well for your article)

        @hourly 0 mastic_segments php -f /srv/data/web/vhosts/mautic.mypop.fr/htdocs/bin/console mautic:segments:update
        @hourly 0 mautic_leadlists php -f /srv/data/web/vhosts/mautic.mypop.fr/htdocs/bin/console mautic:leadlists:update
        @hourly 0 mautic_campaigns_update php -f /srv/data/web/vhosts/mautic.mypop.fr/htdocs/bin/console mautic:campaigns:update
        @hourly 0 mautic_campaigns_trigger php -f /srv/data/web/vhosts/mautic.mypop.fr/htdocs/bin/console mautic:campaigns:trigger
        @hourly 0 mautic_emails_send php -f /srv/data/web/vhosts/mautic.mypop.fr/htdocs/bin/console mautic:emails:send
        @hourly 0 mautic_broadcast php -f /srv/data/web/vhosts/mautic.mypop.fr/htdocs/bin/console mautic:broadcast:send
        @daily 0 mautic_fetch php -f /srv/data/web/vhosts/mautic.mypop.fr/htdocs/bin/console mautic:email:fetch
        @daily 0 mautic_import php -f /srv/data/web/vhosts/mautic.mypop.fr/htdocs/bin/console mautic:import
        @daily 0 mautic_social php -f /srv/data/web/vhosts/mautic.mypop.fr/htdocs/bin/console mautic:social:monitoring
        @weekly 0 mautic_maxmind_dl php -f /srv/data/web/vhosts/mautic.mypop.fr/htdocs/bin/console mautic:iplookup:download
        @weekly 0 mautic_maxmind_donotsell php -f /srv/data/web/vhosts/mautic.mypop.fr/htdocs/bin/console mautic:donotsell:download
        @weekly 0 mautic_maxmind php -f /srv/data/web/vhosts/mautic.mypop.fr/htdocs/bin/console mautic:max-mind:purge

        However, I still have issues as the Upcoming emails are not showing up as the planned email. I had once one campaign and then nothing.

        Reply
        • jos0405

          says:

          Are the emails published?
          These contacts, where the upcoming emails are not showing – did they go through the campaign already?
          When you open a contact who supposed to be in the campaign, can you see them in there?
          Did you wait at least 20 min? Based on your settings it can be up to 20 min until all the cron runs through.

          Reply
          • Paul-Henri Brunet

            says:

            – Emails published
            – Contacts have been added successfully to the campaign
            – Yes I can see them
            – Yes I wait but I may have interrupt something because I was troubleshooting… I will try again and wait fully 30mn. Noted!

  • Luca

    says:

    Hi Joey,
    I am using your Multidomain plugin and I have separate login urls, one for each domain (m.site1.com/s/ – m.site2.com/s/…).

    Shall I duplicate my cronjobs to include the other domains?

    Reply
    • jos0405

      says:

      Hello Luca, this is not what our domain plugin does. It would only overwrite tracking links (unsub, webview and tracking pixel) when you send out emails. In order to enable it you needed to create a CNAME for the second domain. When you open the page with the other domain, it will automatically work on that domain, but it is just because you have that CNAME set up. The new domain is a canonical name of the old domain. It didn’t double your install, just made sure to “be known under another name” as well.
      In short: no need to set other cronjobs.

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *