Mautic Community Forums

Cron jobs issues

Your software
My Mautic version is: 3.1.0
My PHP version is: 7.3.25
My Database type and version is: Mysql 5.7

Your problem
My problem is: cron jobs fail.

These errors are showing in the log:
In AbstractMySQLDriver.php line 93:

  An exception occurred in driver: SQLSTATE[HY000] [2002] No such file or directory  

In PDOConnection.php line 31:
  SQLSTATE[HY000] [2002] No such file or directory  

In PDOConnection.php line 27:
  SQLSTATE[HY000] [2002] No such file or directory 

Steps I have tried to fix the problem:
Cron jobs work when run with sudo, but fail with www-data user. I’ve checked all files and folders have user and group set to www-data. All directories are 755 and files are 644.

Not sure why the user www-data can’t run cron.

1 Like

This issue is still happening with the mautic:v3 docker image.

I have checked the permimssions on directories as well. Attaching a screenshot of mautic admin panel where it shows the permissions

I can replicate the same error when i run

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

It also fails if I run it with
sudo -u root php /var/www/html/bin/console mautic:segments:update

The command works fine if I run it without sudo
php /var/www/html/bin/console mautic:segments:update

Any help is deeply appreciated!

1 Like

@amit.kumar, do you have any update on this?

I am having the same issue and can’t figure out the reason for this. My cron jobs are just not able to connect to mysql when running with “sudo -u”, neither with root nor with www-data. As you described when running without “sudo -u” it works.

Who is the webserver user? You should run in the name of that entity.

Hi, I finally found out what the problem was. I was running Mautic in a Docker container which connected to the DB on the host system. When I set up Mautic I may have used an internal Docker IP to connect the application to the DB and I suspect that at that time the IP address was written into app/config/local.php. Later I changed the host to “host.docker.internal” but that was not applied in local.php. So I just set that name instead of the IP address and it started working.

If anyone knows why the settings from local.php only apply to cron jobs (and the command with “sudo -u”) please let me know, it would be great to have an explanation for this weird behaviour.