Local Community

Error establishing a database connection after switching from PHP 7.3.5 to PHP 7.4.1

Error establishing a database connection once upgrading PHP version from 7.3.5 to 7.4.1
Local 5.4.1 for macOS

Hi Tobias,

Does this issue persist even after restarting the site?

Yes, even tried to reinstall local and tried different local sites.

Got it. Can you please provide your local-lightning.log file? See How do I retrieve Local's log file? for instructions on how to do so.


Additionally, are new sites that use 7.3 or 5.6 able to connect to the database?

Yes

Got it. Can you please provide your local-lightning.log file? See How do I retrieve Local’s log file? for instructions on how to do so.

Some sites still run 7.3.5 as they don’t work on 7.4.1, and some new installs since 7.4.1 were available to run smooth. But upgrading have not been successfully working for me.

Allow me to share over email, do you mind sharing your email and I send it over there.

Sure. It’s clay@getflywheel.com

I’m running into the same problems after updating to 5.4.1

Sites are unable to connect to MySQL server either in the wp install or via Adminer.

MySQL 8.0.10
PHP 7.4.1

Sites are working on PHP 7.3.5

Logs are attached. local-lightning.log (547.0 KB)

Thanks for the log files @claytoncollie1 and @alriksson!

Unfortunately, I’m not seeing anything in the log files that’s related to this problem. One thing that might help uncover more details is the PHP/MySQL log file in the site’s logs directory.

Feel free to e-mail them to me if you don’t want to share them publicly.


@claytoncollie1 before Local 5.4.1, PHP 7.4.1 worked for you?

I was using 7.3.5 before upgrading so I am not sure if it worked beforehand.

@claytoncollie1,

Thanks for sending over the log files. Again, not seeing anything particularly obvious there.

Here’s one thing that you both can try:

  1. Switch the Local site back to PHP 7.3.5
  2. Quit Local
  3. Browse to ~/Library/Application Support/Local/lightning-services and remove the PHP services in that directory (for example: php-7.4.1+5)
  4. Re-open Local
  5. Swap the Local site back to PHP 7.4.1

@clay Remove the folder php-7.4.1+5 right?
https://tppr.me/q2oeX

But what will happened to sites that already run on 7.4.1?

I’ve been having the same issue on both 5.4.1 and 5.4.2. I’ve narrowed it down a bit:

  • newly created sites - no problem switching
  • sites created before Local 5.4, can switch to PHP 7.4 without problem if they were using MySQL 5.7.28
  • sites created before Local 5.4, cannot switch to PHP 7.4 without problem if they were using MySQL 8.0.16

For those sites where switching didn’t work, the symptoms were:

  • connection to the site was very slow (>10 seconds)
  • eventually returned the following errors:
Warning: mysqli_real_connect(): Unexpected server response while doing caching_sha2 auth: 109 in /Users/.../app/public/wp-includes/wp-db.php on line 1633
Warning: mysqli_real_connect(): (HY000/2006): MySQL server has gone away in /Users/.../app/public/wp-includes/wp-db.php on line 1633

It wasn’t too hard to fix. For a site which wasn’t working on PHP7.4:

  • move the site files to a new location
  • delete the site in Local
  • recreate the site in Local, stop the site
  • replace the app directory in the new site with the app directory from the old site files
  • restart the site in Local
  • import the DB

Switching between PHP 7.3 and 7.4 works as expected.

@clay if there are any logs it would be helpful to see, let me know what to send.

1 Like

These steps did not work for me.

I am still getting the same MySQL not found errors when switching to 7.4.1

Latest verson 5.5.1 with NGINX I receive following while trying to upgrade.

Error: Error: Command failed: /Users/username/Library/Application Support/Local/lightning-services/php-7.4.1+5/bin/darwin/bin/php /Applications/Local.app/Contents/Resources/extraResources/bin/wp-cli/wp-cli.phar --path=/Users/username/Local Sites/test-site/app/public --require=/Applications/Local.app/Contents/Resources/extraResources/bin/wp-cli/local-wpcli-error-reporting.php rewrite flush --hard
Error: Error establishing a database connection.

    at ChildProcess.exithandler (child_process.js:308:12)
    at ChildProcess.emit (events.js:203:13)
    at ChildProcess.EventEmitter.emit (domain.js:476:20)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)

And I can no longer start the site

Error: TypeError: Cannot read property 'socket' of null
    at NginxService.get configVariables [as configVariables] (/Applications/Local.app/Contents/Resources/extraResources/lightning-services/nginx-1.16.0+3/lib/NginxService.js:66:33)
    at ConfigTemplatesService.<anonymous> (/Applications/Local.app/Contents/Resources/app.asar/main/sites/ConfigTemplatesService.js:1:4132)
    at Generator.next (<anonymous>)
    at _0x96b3ed (/Applications/Local.app/Contents/Resources/app.asar/main/sites/ConfigTemplatesService.js:1:1405)

Hi, I had the same error when I try to stard my site:

Error: TypeError: Cannot read property ‘socket’ of null
at NginxService.get configVariables [as configVariables] (/Applications/Local.app/Contents/Resources/extraResources/lightning-services/nginx-1.16.0+3/lib/NginxService.js:66:33)
at ConfigTemplatesService. (/Applications/Local.app/Contents/Resources/app.asar/main/sites/ConfigTemplatesService.js:1:4132)
at Generator.next ()
at _0x96b3ed (/Applications/Local.app/Contents/Resources/app.asar/main/sites/ConfigTemplatesService.js:1:1405)

Anyone have any solution or advice?

Thank’s a lot!

1 Like

Hey @Carme,

I just ran into the same issue today. Were you able to find a solution?

Thanks,
Ravneet

I had the same issue. Just deleted the site and created it again.

2 Likes

When I tried upgrading to PHP 7.4 I ran into this error


After the failed upgrade the site is unusable and cannot be downgraded. When I try to start it I see the error “Error: TypeError: Cannot read property ‘socket’ of nullat NginxService.get configVariables [as configVariables] (/Applications/Local.app/Contents/Resources/extraResources/lightning-services/nginx-1.16.0+3/lib/NginxService.js:66:33)…”.

I fixed it now by following the advice of @IsaacBen.

Exactly what has happened to me. No ability in Local to downgrade PHP back to 7.3.5. Any way to manually downgrade PHP back to 7.3.5? Cannot start site to perform other actions with this error.

While this is still a problem, I did get the development site I’ve been working on back up and running by following the instructions from @rowatt above. Essentially creating a new site, copying the app folder and then importing the DB.