# Exception: SQLSTATE\[HY000\] \[2002\] Connection refused

**URL:** <https://community.passbolt.com/t/exception-sqlstate-hy000-2002-connection-refused/2694>\
**Category:** Installation Issues\
**Created:** [April 27, 2020, 3:07pm UTC](https://community.passbolt.com/t/exception-sqlstate-hy000-2002-connection-refused/2694 "2020-04-27T15:07:33Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![vig](https://avatars.discourse-cdn.com/v4/letter/v/8797f3/32.png) [@vig](https://community.passbolt.com/u/vig)\
**Post date:** [April 27, 2020, 3:07pm UTC](https://community.passbolt.com/t/exception-sqlstate-hy000-2002-connection-refused/2694/1 "2020-04-27T15:07:34Z")

</div>

## Open source password manager for teams

## Healthcheck shell

Environment

[PASS] PHP version 7.0.33-0+deb9u7.  
[PASS] PCRE compiled with unicode support.  
[PASS] The temporary directory and its content are writable.  
[PASS] The public image directory and its content are writable.  
[PASS] The logs directory and its content are writable.  
[PASS] GD or Imagick extension is installed.  
[PASS] Intl extension is installed.  
[PASS] Mbstring extension is installed.

Config files

[PASS] The application config file is present  
[PASS] The passbolt config file is present

Core config

[PASS] Debug mode is off.  
[PASS] Cache is working.  
[PASS] Unique value set for security.salt  
[PASS] Full base url is set to [https://pwd.lxxx.fr](https://pwd.lxxx.fr)  
[PASS] App.fullBaseUrl validation OK.  
[FAIL] Could not reach the /healthcheck/status with the url specified in App.fullBaseUrl  
[HELP] Check that the domain name is correct in config/passbolt.php  
[HELP] Check the network settings

SSL Certificate

[FAIL] SSL peer certificate does not validate  
[FAIL] Hostname does not match when validating certificates.  
[WARN] Using a self-signed certificate

Database

[PASS] The application is able to connect to the database  
[PASS] 24 tables found  
[PASS] Some default content is present  
[PASS] The database schema up to date.

GPG Configuration

[PASS] PHP GPG Module is installed and loaded.  
[PASS] The environment variable GNUPGHOME is set to /var/www/.gnupg.  
[PASS] The directory /var/www/.gnupg containing the keyring is writable by the webserver user.  
[PASS] The server gpg key is not the default one  
[PASS] The public key file is defined in config/passbolt.php and readable.  
[PASS] The private key file is defined in config/passbolt.php and readable.  
[PASS] The server key fingerprint matches the one defined in config/passbolt.php.  
[PASS] The server public key defined in the config/passbolt.php (or environment variables) is in the keyring.  
[PASS] There is a valid email id defined for the server key.  
[PASS] The public key can be used to encrypt a message.  
[PASS] The private key can be used to sign a message.  
[PASS] The public and private keys can be used to encrypt and sign a message.  
[PASS] The private key can be used to decrypt a message.  
[PASS] The private key can be used to decrypt and verify a message.  
[PASS] The public key can be used to verify a signature.

Application configuration

[PASS] Using latest passbolt version (2.12.1).  
[PASS] Passbolt is configured to force SSL use.  
[PASS] App.fullBaseUrl is set to HTTPS.  
[PASS] Selenium API endpoints are disabled.  
[PASS] Search engine robots are told not to index content.  
[PASS] Registration is closed, only administrators can add users.  
[PASS] Serving the compiled version of the javascript app  
[PASS] All email notifications will be sent.

3 error(s) found. Hang in there!

Hi all,

I’ve installed Passbolt in 2018 from 1.0.12 on a Debian 9, and followed the life project till 2.12.1 …

The system works perfectly, a real pleasure to use. Didn’t find any problem during the use, but, since severals weeks, i receive mail notifications from my Passbolt Server  
(su -c “/var/www/passbolt/bin/cake EmailQueue.sender \>\> /var/log/passbolt.log” -s /bin/bash www-data):

```
Exception: SQLSTATE[HY000] [2002] Connection refused in [/var/www/passbolt/vendor/cakephp/cakephp/src/Database/Driver.php, line 92]
su: Cannot make/remove an entry for the specified session    

```

I don’t understand why, and what are the consequences ?

Could you please give me some help ?

Best regards

---

<div class="post-metadata">

**Author:** ![diego](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.passbolt.com/diego/32/16_2.png) [@diego](https://community.passbolt.com/u/diego)\
**Post date:** [April 27, 2020, 3:34pm UTC](https://community.passbolt.com/t/exception-sqlstate-hy000-2002-connection-refused/2694/2 "2020-04-27T15:34:39Z")

</div>

Hi @vig

Thanks for your kind words about passbolt! We really appreciate them.

Let me understand one thing about your message. The error you posted comes from manually executing `su -c “/var/www/passbolt/bin/cake EmailQueue.sender >> /var/log/passbolt.log” -s /bin/bash www-data` ?

---

<div class="post-metadata">

**Author:** ![vig](https://avatars.discourse-cdn.com/v4/letter/v/8797f3/32.png) [@vig](https://community.passbolt.com/u/vig)\
**Post date:** [April 27, 2020, 3:47pm UTC](https://community.passbolt.com/t/exception-sqlstate-hy000-2002-connection-refused/2694/3 "2020-04-27T15:47:24Z")

</div>

Hi Diego,

Thank you for your quick reply,

this command is executed by a cron every minute to send mail.

---

<div class="post-metadata">

**Author:** ![diego](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.passbolt.com/diego/32/16_2.png) [@diego](https://community.passbolt.com/u/diego)\
**Post date:** [April 27, 2020, 4:10pm UTC](https://community.passbolt.com/t/exception-sqlstate-hy000-2002-connection-refused/2694/4 "2020-04-27T16:10:02Z")

</div>

Sorry I think there is a misunderstanding. What I meant is have you tried to run that command manually and check if you get an error?

Considering the healthcheck log you posted where the database connection seems to work it looks like the environment when executing the cron job has some problems.

---

<div class="post-metadata">

**Author:** ![vig](https://avatars.discourse-cdn.com/v4/letter/v/8797f3/32.png) [@vig](https://community.passbolt.com/u/vig)\
**Post date:** [April 27, 2020, 4:51pm UTC](https://community.passbolt.com/t/exception-sqlstate-hy000-2002-connection-refused/2694/5 "2020-04-27T16:51:02Z")

</div>

oh sorry,

yes i tried to run it manually, and didn’t get any error. It appear only with Cron.

---

<div class="post-metadata">

**Author:** ![vig](https://avatars.discourse-cdn.com/v4/letter/v/8797f3/32.png) [@vig](https://community.passbolt.com/u/vig)\
**Post date:** [April 28, 2020, 1:15pm UTC](https://community.passbolt.com/t/exception-sqlstate-hy000-2002-connection-refused/2694/6 "2020-04-28T13:15:02Z")

</div>

Do you think this is a False Positive error message ?

---

<div class="post-metadata">

**Author:** ![diego](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.passbolt.com/diego/32/16_2.png) [@diego](https://community.passbolt.com/u/diego)\
**Post date:** [April 28, 2020, 1:33pm UTC](https://community.passbolt.com/t/exception-sqlstate-hy000-2002-connection-refused/2694/7 "2020-04-28T13:33:23Z")

</div>

Hi @vig,

Which user is running the cron job?

---

<div class="post-metadata">

**Author:** ![vig](https://avatars.discourse-cdn.com/v4/letter/v/8797f3/32.png) [@vig](https://community.passbolt.com/u/vig)\
**Post date:** [April 28, 2020, 1:44pm UTC](https://community.passbolt.com/t/exception-sqlstate-hy000-2002-connection-refused/2694/8 "2020-04-28T13:44:37Z")

</div>

Hi Diego,

This is ROOT Cron job.

---

<div class="post-metadata">

**Author:** ![diego](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.passbolt.com/diego/32/16_2.png) [@diego](https://community.passbolt.com/u/diego)\
**Post date:** [April 28, 2020, 1:54pm UTC](https://community.passbolt.com/t/exception-sqlstate-hy000-2002-connection-refused/2694/9 "2020-04-28T13:54:39Z")

</div>

Considering the su message you see let’s try try the following:

Define a system wide cron job in /etc/crontab like this:

`* * * * * www-data /var/www/passbolt/bin/cake EmailQueue.sender`

Of course disable your old cron job 😃

---

<div class="post-metadata">

**Author:** ![vig](https://avatars.discourse-cdn.com/v4/letter/v/8797f3/32.png) [@vig](https://community.passbolt.com/u/vig)\
**Post date:** [April 28, 2020, 2:09pm UTC](https://community.passbolt.com/t/exception-sqlstate-hy000-2002-connection-refused/2694/10 "2020-04-28T14:09:34Z")

</div>

Thank you very Much for your help Dear Diego.

I’m going to test this solution.

I will keep you in touch.

Cheers

---

<div class="post-metadata">

**Author:** ![vig](https://avatars.discourse-cdn.com/v4/letter/v/8797f3/32.png) [@vig](https://community.passbolt.com/u/vig)\
**Post date:** [April 29, 2020, 12:37pm UTC](https://community.passbolt.com/t/exception-sqlstate-hy000-2002-connection-refused/2694/11 "2020-04-29T12:37:50Z")

</div>

Hi,

so, i did the modification with `www-data` cron job.

Now i’m getting this error :

```
PHP Notice: PDO::__construct(): send of 119 bytes failed with errno=32 Broken pipe in /var/www/passbolt/vendor/cakephp/cakephp/src/Database/Driver.php on line 92
Exception: SQLSTATE[HY000] [2006] MySQL server has gone away in [/var/www/passbolt/vendor/cakephp/cakephp/src/Database/Driver.php, line 92]

```

Regards

---

<div class="post-metadata">

**Author:** ![diego](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.passbolt.com/diego/32/16_2.png) [@diego](https://community.passbolt.com/u/diego)\
**Post date:** [April 29, 2020, 1:32pm UTC](https://community.passbolt.com/t/exception-sqlstate-hy000-2002-connection-refused/2694/12 "2020-04-29T13:32:27Z")

</div>

It is a bit weird your issue,

Could it be there is no enough memory on the server for your setup?  
Do you have any mysql error log?

---

<div class="post-metadata">

**Author:** ![vig](https://avatars.discourse-cdn.com/v4/letter/v/8797f3/32.png) [@vig](https://community.passbolt.com/u/vig)\
**Post date:** [April 29, 2020, 2:09pm UTC](https://community.passbolt.com/t/exception-sqlstate-hy000-2002-connection-refused/2694/13 "2020-04-29T14:09:32Z")

</div>

The server is big enough, with 8 Go of Memory and huge free disk space.

About MySQL Error, nothing .

Which user is supposed to own Driver.php ?

---

<div class="post-metadata">

**Author:** ![diego](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.passbolt.com/diego/32/16_2.png) [@diego](https://community.passbolt.com/u/diego)\
**Post date:** [April 29, 2020, 2:15pm UTC](https://community.passbolt.com/t/exception-sqlstate-hy000-2002-connection-refused/2694/14 "2020-04-29T14:15:00Z")

</div>

If you run on debian nginx and apache should use www-data as user to run. So the www-data user should be able to read and execute most of the passbolt files.  
Some of these files www-data requires permission to write such as the files under the `/var/www/passbolt/tmp` directory, the logs and the public images directory `/var/www/passbolt/webroot/img/public`

Easiest solution is to make www-data owner of all the passbolt files.

---

<div class="post-metadata">

**Author:** ![vig](https://avatars.discourse-cdn.com/v4/letter/v/8797f3/32.png) [@vig](https://community.passbolt.com/u/vig)\
**Post date:** [April 30, 2020, 12:38pm UTC](https://community.passbolt.com/t/exception-sqlstate-hy000-2002-connection-refused/2694/15 "2020-04-30T12:38:28Z")

</div>

Hi Diego,

How are you doing ?

So i’ve check permission, everything is ok, files are owned by `www-data`.

Still have 3 or 4 error messages per day.

```
Warning Error: PDO::beginTransaction(): MySQL server has gone away in [/var/www/passbolt/vendor/cakephp/cakephp/src/Database/Driver.php, line 184]

 2020-04-29 23:25:37 Warning: Warning (2): PDO::beginTransaction(): MySQL server has gone away in [/var/www/passbolt/vendor/cakephp/cakephp/src/Database/Driver.php, line 184]

Warning Error: PDO::beginTransaction(): Error reading result set's header in [/var/www/passbolt/vendor/cakephp/cakephp/src/Database/Driver.php, line 184]

2020-04-29 23:25:41 Warning: Warning (2): PDO::beginTransaction(): Error reading result set's header in [/var/www/passbolt/vendor/cakephp/cakephp/src/Database/Driver.php, line 184]

Exception: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away in [/var/www/passbolt/vendor/cakephp/cakephp/src/Database/Driver.php, line 184]

```

There is no error in mariadb logs.

I don’t have any idea.

---

<div class="post-metadata">

**Author:** ![diego](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.passbolt.com/diego/32/16_2.png) [@diego](https://community.passbolt.com/u/diego)\
**Post date:** [April 30, 2020, 1:09pm UTC](https://community.passbolt.com/t/exception-sqlstate-hy000-2002-connection-refused/2694/16 "2020-04-30T13:09:04Z")

</div>

Could it be your datbase server having issues?

[https://dev.mysql.com/doc/refman/8.0/en/gone-away.html](https://dev.mysql.com/doc/refman/8.0/en/gone-away.html)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex031/uploads/passbolt/original/2X/b/bee7d3f9329f668000d46e9fcb2e5db1e9d31348.svg) [@system](https://community.passbolt.com/u/system)\
**Post date:** [May 5, 2020, 1:09pm UTC](https://community.passbolt.com/t/exception-sqlstate-hy000-2002-connection-refused/2694/17 "2020-05-05T13:09:04Z")

</div>

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.

---

<div class="post-metadata">

**Author:** ![remy](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.passbolt.com/remy/32/17_2.png) [@remy](https://community.passbolt.com/u/remy)\
**Post date:** [May 6, 2020, 9:36pm UTC](https://community.passbolt.com/t/exception-sqlstate-hy000-2002-connection-refused/2694/18 "2020-05-06T21:36:36Z")

</div>


