OpemEMR on Cloud Run Instance not able to connect with Cloud SQL Mysql using SSL

Situation
Unable to connect OpenEMR Google Cloud Run instance to Google Cloud SQL MySQL

OpenEMR Version
OpenEMR 8.0.0 on Google Cloud Run built using Dockerfile

Browser:
Chrome

Operating System
Google Cloud Run

Search
Yes couldn’t find anything

Logs

[php:error] [pid 102:tid 102] [client 169.254.169.126:30066] PHP Fatal error:  Uncaught Error: Call to a member function prepare() on false in /var/www/localhost/htdocs/openemr/vendor/adodb/adodb-php/drivers/adodb-mysqli.inc.php:1353\nStack trace:\n#0 /var/www/localhost/htdocs/openemr/vendor/adodb/adodb-php/adodb.inc.php(1613): ADODB_mysqli->_query()\n#1 /var/www/localhost/htdocs/openemr/vendor/adodb/adodb-php/drivers/adodb-mysqli.inc.php(1235): ADOConnection->_Execute()\n#2 /var/www/localhost/htdocs/openemr/library/ADODB_mysqli_log.php(65): ADODB_mysqli->execute()\n#3 /var/www/localhost/htdocs/openemr/library/sql.inc.php(234): ADODB_mysqli_log->ExecuteNoLog()\n#4 /var/www/localhost/htdocs/openemr/library/translation.inc.php(65): sqlStatementNoLog()\n#5 /var/www/localhost/htdocs/openemr/library/htmlspecialchars.inc.php(225): xl()\n#6 /var/www/localhost/htdocs/openemr/library/htmlspecialchars.inc.php(245): hsc_private_xl_or_warn()\n#7 /var/www/localhost/htdocs/openemr/library/sql.inc.php(581): xlt()\n#8 /var/www/localhost/htdocs/openemr/library/sql.inc.php(98): HelpfulDie()\n#9 /var/www/localhost/htdocs/openemr/interface/globals.php(390): require_once('...')\n#10 /var/www/localhost/htdocs/openemr/interface/login/login.php(52): require_once('...')\n#11 {main}\n  thrown in /var/www/localhost/htdocs/openemr/vendor/adodb/adodb-php/drivers/adodb-mysqli.inc.php on line 1353

Hi Everyone,
I am new here.

I have been for a long time trying to connect my OpenEMR Cloud Run instance with my Google Cloud MySQL with SSL enabled.

Prior to enabling SSL in Cloud SQL, I was able to connect without issues.

After enabling, the browser only shows the message


Check that you can ping the server <Ip address>

Service account is configured too.

I am connecting with Internal IP address.

I have tried adding mysql-ca in default\documents\certificates\

Also tried with adding mysql-cert and mysql-key. It didnt work and gave the same error.

Any help would be really appreciated.

Thanks.

@ashish.varghese Make sure your database details or credentials is correct on below location /var/www/localhost/htdocs/openemr/sites/default/sqlconf.php

Two things are probably going on, and only one of them is the real problem.

The error in your log hides the real one. “Call to a member function prepare() on false” comes from OpenEMR’s error page itself. When the database connection fails, the page tries to translate its message, which needs the database, and dies. The real failure is the one before it, the one the browser shows as “Check that you can ping the server”.

With SSL, PHP checks the database server’s name. Once mysql-ca is in sites/default/documents/certificates, OpenEMR connects over SSL, and PHP checks two things about the server’s certificate: that mysql-ca signed it, and that it names the host in sqlconf.php. Cloud SQL’s server certificate names the instance, not its internal IP, so connecting by IP fails that check. PHP reports it only as “Cannot connect to MySQL using SSL” (error 2002), which looks like the server isn’t there at all. Adding mysql-cert and mysql-key doesn’t change that check, which is why it made no difference.

What usually works on Cloud Run:

  • Cloud SQL’s own connection (the Cloud SQL connection on the Cloud Run service, or the Cloud SQL Auth Proxy) encrypts the traffic for you, with no certificates in OpenEMR. Then leave mysql-ca, mysql-cert and mysql-key out of documents/certificates.
  • Or connect by a name that’s in the server’s certificate rather than the IP. That’s harder to arrange with Cloud SQL.

To see exactly what’s refused, the install doctor reads your site’s settings and the certificates folder, connects the way OpenEMR does, and says whether mysql-ca didn’t sign the server’s certificate or which names the certificate holds instead of your host:

php openemr-doctor.php --openemr=/var/www/localhost/htdocs/openemr --site=default

It’s openemr-doctor.php from Release v0.3.7: the install doctor checks MySQL over SSL · anun333/openemr-reference · GitHub. It only reads, and never prints a password or a key. If you post its “Database” lines, we can see which of the two it is.

Thanks for the response.
The database creds were correct. I was able to connect when SSL was disabled.

Thanks so much for your help.

This helped me resolve the issue.

Cloud SQL’s server certificate names the instance, not its internal IP, so connecting by IP fails that check.

This did the trick.

Thanks a TON!

Hi @ashish.varghese ! Great to hear it was solved. Would you mind adding a preffix to the thread title like `[SOLVED] OpemEMR on Cloud Run Instance not able to connect with Cloud SQL Mysql using SSL` ? thanks!

EDIT:

Now a chkbox is available to mark as ‘‘solved’’ next to the thread.