# Cron jobs issues

**URL:** <https://forum.mautic.org/t/cron-jobs-issues/18470>\
**Category:** Product Support\
**Created:** [March 7, 2021, 11:09am UTC](https://forum.mautic.org/t/cron-jobs-issues/18470 "2021-03-07T11:09:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![amit.kumar](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/amit.kumar/32/580_2.png) [@amit.kumar](https://forum.mautic.org/u/amit.kumar)\
**Post date:** [March 7, 2021, 11:09am UTC](https://forum.mautic.org/t/cron-jobs-issues/18470/1 "2021-03-07T11:09:10Z")

</div>

**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.

---

<div class="post-metadata">

**Author:** ![amit.kumar](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/amit.kumar/32/580_2.png) [@amit.kumar](https://forum.mautic.org/u/amit.kumar)\
**Post date:** [May 18, 2021, 4:24pm UTC](https://forum.mautic.org/t/cron-jobs-issues/18470/2 "2021-05-18T16:24:01Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/2X/7/702310055e6e7865900d82eac5c115b278e78dff.png)

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!

---

<div class="post-metadata">

**Author:** ![guentr](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/guentr/32/1045_2.png) [@guentr](https://forum.mautic.org/u/guentr)\
**Post date:** [July 20, 2021, 7:59am UTC](https://forum.mautic.org/t/cron-jobs-issues/18470/3 "2021-07-20T07:59:00Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [July 21, 2021, 7:04am UTC](https://forum.mautic.org/t/cron-jobs-issues/18470/4 "2021-07-21T07:04:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![guentr](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/guentr/32/1045_2.png) [@guentr](https://forum.mautic.org/u/guentr)\
**Post date:** [July 21, 2021, 7:23am UTC](https://forum.mautic.org/t/cron-jobs-issues/18470/5 "2021-07-21T07:23:39Z")

</div>

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.
