Mautic Community Forums

Cronjob not working on mautic 3.0.1

Your software
My Mautic version is:3.0.1
My PHP version is:7.3

Your problem
My problem is: corn job not working
I’m trying to import contacts in the background but nothing happens
These errors are showing in the log:

Steps I have tried to fix the problem: fresh install and clean the cash and change the directory to bin/console instead of app/console
this is my setting

3 Likes

What happens if you run some commands manually? E.g. /var/www/html/mautic/bin/console mautic:campaigns:update? Do you see any errors or does the process complete successfully?

yes the process complete successfully i tried running commands is working fine no errors, but te corn not working automatically

cron log

It could be a permissions issue: which http engine are you using?

With Apache, try resetting the permissions to www-data and then execute the cron job as www-data, not root.

See the main article here:
https://docs.mautic.org/en/troubleshooting/file-ownership-and-permissions

You’ll have to change the app/cache and app/logs folders to var/ with v.3.0.0+
sudo -s
chown -R www-data:www-data /var/www/html/mautic
cd /var/www/html/mautic
find . -type d -not -perm 755 -exec chmod 755 {} +
find . -type f -not -perm 644 -exec chmod 644 {} +
chmod -R g+w var/cache/ var/logs/ app/config/
chmod -R g+w media/files/ media/images/ translations/

and then change the crontab file to use ww-data (or assign those tasks to www-data user crontab):
00,15,30,45 * * * * www-data /usr/bin/php /var/www/html/mautic/bin/console mautic:segments:update
05,20,35,50 * * * * www-data /usr/bin/php /var/www/html/mautic/bin/console mautic:campaigns:update
10,25,40,55 * * * * www-data /usr/bin/php /var/www/html/mautic/bin/console mautic:campaigns:trigger

I’d follow this suggestion as well:
It is HIGHLY recommended that you stagger the following required jobs so as to not run the exact same minute.

as seen here:
https://docs.mautic.org/en/setup/cron-jobs

Thanks for your post. It was extremely helpful and got my cron jobs sorted out. I had spent a lot of the last few days reading through sites and posts, most of which referred to mautic version 2 and their suggestions did not fit to the current version or did not work. Your suggestion to change the permissions as per the earlier mautic guide and providing the updated commands along with www-data user worked fine.

1 Like

I’m glad it helped!

I had a similar issue and it took a while to figure out the cronjob, running as root, was making a mess out of the Mautic permissions.

Hello everyone,

I have the same problem as batrachi but as a newbie, I don’t know how to modify the :

app/cache and app/logs folders to var/ with v.3.0.0+
sudo -s

if anyone can tell me how to do this I will be grateful.

thank you

You’re right, that was just a quick hint quite obscure. When I wrote that post, the instructions given in the article:
https://docs.mautic.org/en/troubleshooting/file-ownership-and-permissions

were referring to the wrong folders (app/cache and app/logs) instead of the new ones defined from version 3.0.0 and above (var/cache and var/logs).

The instructions look correct now, so you can just follow them.

I’m assuming you have ssh access and sudo permission to root. You also need to know the “path/to/mautic” folder where Mautic is installed (that’s “/var/www/html/mautic/” in my server). It’s easier if you save that path in a shell variable, like “mauticPATH”. The complete set of commands is:

sudo -s
mauticPATH=/var/www/html/mautic/
chown -R www-data:www-data ${mauticPATH}
cd ${mauticPATH}
find . -type d -not -perm 755 -exec chmod 755 {} +
find . -type f -not -perm 644 -exec chmod 644 {} +
chmod -R g+w ${mauticPATH}var/cache/
chmod -R g+w ${mauticPATH}var/logs/
chmod -R g+w ${mauticPATH}app/config/
chmod -R g+w ${mauticPATH}media/files/
chmod -R g+w ${mauticPATH}media/images/
chmod -R g+w ${mauticPATH}translations/

Then you need to change the /etc/crontab file:

vim /etc/crontab

Add the crontab jobs for the www-data user:

00,15,30,45 * * * * www-data /usr/bin/php /var/www/html/mautic/bin/console mautic:segments:update
05,20,35,50 * * * * www-data /usr/bin/php /var/www/html/mautic/bin/console mautic:campaigns:update
10,25,40,55 * * * * www-data /usr/bin/php /var/www/html/mautic/bin/console mautic:campaigns:trigger

You can also add some optional jobs (uncomment the desired ones):

02,17,32,47 * * * * www-data /usr/bin/php /var/www/html/mautic/bin/console mautic:emails:send >>/var/www/html/mautic/var/logs/cron.log 2>&1
#07,22,37,52 * * * * www-data /usr/bin/php /var/www/html/mautic/bin/console mautic:emails:fetch
#08,23,38,53 * * * * www-data /usr/bin/php /var/www/html/mautic/bin/console mautic:social:monitoring
#
0 0 7 * * www-data /usr/bin/php /var/www/html/mautic/bin/console mautic:iplookup:download >>/var/www/html/mautic/var/logs/cron.log 2>&1
#0 0 2 * * www-data /usr/bin/php /var/www/html/mautic/bin/console mautic:maintenance:cleanup --days-old=365 >>/var/www/html/mautic/var/logs/cron.log 2>&1

Add " >>/var/www/html/mautic/var/logs/cron.log 2>&1" to save the job output a log file instead of receiving it by email.

Again, I’m assuming you can run php with “/usr/bin/php”. You can check it with this command:

which php

Hope the above helps.