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.

2 Likes

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.

thnx a lot @stefanomarty

i have already the permission

here is my cronjobs on /etc/crontab folder

but on mautic nothing is working !!!

Ok no panic :slight_smile:

Permissions look fine. First of all, what do you mean by “on mautic nothing is working”? I thought your issue was just about making the crontab jobs run, is that correct?

Do the crontab jobs run if you launch the commands manually? I mean, what happens if you run this commands from your terminal:

sudo -u www-data /usr/bin/php /var/www/html/mautic/bin/console mautic:segments:update
sudo -u www-data /usr/bin/php /var/www/html/mautic/bin/console mautic:campaigns:update
sudo -u www-data /usr/bin/php /var/www/html/mautic/bin/console mautic:campaigns:trigger

Do you see any error? How about Mautic web interface, is it running ok?

Mautic is quite a complex platform, you’ll need to follow the instructions step by step (see link in previous post).

my appologise, I didn’t explain my situation well

on mautic, the manual controls work but not the auto one,

e.g.: I created a simple campaign (sergment) => send email

when I add my emails (3) to the segment, the campaign don’t send the emails

here my mannual commandes

must i change something in the mautic general setting !!

thnx again :slight_smile:

Looks like you have no contacts added to the segment.

Could you post the “Segment” screenshot of your system? Something like this:

my emails for the test

Ok, so the contacts where already added to segment #8, good.

It’s not easy to see what’s happening there, I would check the following:

  • Configuration --> Email Settings: is test connection ok? can you send the test email?
  • Email handling: is it set to “send immediately” or “queue”?
  • If set to “queue”, have you tried sending the queue manually with the command:
sudo -s www-data /usr/bin/php /var/www/html/mautic/bin/console mautic:emails:send

What’s the command output? What do you see in the log?

If all the above is ok, there’s probably a constrain somewhere else preventing the emails to be sent.

We need somebody else involved here, as this is probably beyond my level of Mautic expertise (which is very low :slight_smile:)

image

i creat an queue email on the campaign

can i know what u have in ur mautic general setting ??

I’ve changed everything, so I don’t know if the path is good or not.

and how can I be sure it’s good???

Sorry, my fault, the correct command is:

sudo -u www-data /usr/bin/php /var/www/html/mautic/bin/console mautic:emails:send

That’s “-u”, not “-s”

Anyway if you set the configuration to send email immediately you don’t need to elaborate the queue, emails should be sent without the cron job.

Don’t know what to say at this point, you need to check every step, see if your smtp service receives the emails, check the logs, etc.

1 Like

if the manually commande work, so we are sure that the prob is the cronjobs no ???

Wait, the “cache” folder is in “var”, not in “bin”!
I have the “mautic folder” in /opt instead of /var/www/html, but that makes no difference (as long as you put the correct folder in your crontab jobs):

Check your install with:

sudo -s
mauticPATH=/var/www/html/mautic/
cd ${mauticPATH}
ls -la var
# Here you should see the cache folder among others:
# drwxr-xr-x  6 www-data www-data 4096 Jun 29 20:06 ./
# drwxr-xr-x 11 www-data www-data 4096 Dec  3 07:52 ../
# drwxrwxr-x  5 www-data www-data 4096 Dec  3 07:52 cache/
# -rw-r--r--  1 www-data www-data   14 Jun 29 20:04 .htaccess
# drwxrwxr-x  2 www-data www-data 4096 Dec  3 15:41 logs/
# drwxr-xr-x  2 www-data www-data 4096 Jul 15 09:57 spool/
# drwxr-xr-x  4 www-data www-data 4096 Dec  3 07:52 tmp/
#
ls -la bin
# Here you'd see something like this:
# drwxr-xr-x  2 www-data www-data 4096 Dec  3 07:52 ./
# drwxr-xr-x 11 www-data www-data 4096 Dec  3 07:52 ../
# -rw-r--r--  1 www-data www-data 1528 Dec  3 07:52 console
# -rw-r--r--  1 www-data www-data   13 Dec  3 07:52 .htaccess
1 Like