Can't connect to PlanetScale with Symfony app

Hi, I have problem with connecting Symfony app with PlanetScale. This is the error I am getting:

An exception occurred in the driver: SQLSTATE[HY000] [1105] unknown error: Code: UNAVAILABLE  
  server does not allow insecure connections, client must use SSL/TLS   

This is my DATABASE_URL suggested by PlanetScale:

DATABASE_URL='mysql://57d19a8h5xauk6bbn3s3:************@aws.connect.psdb.cloud:3306/xnonxix?serverVersion=8.0'

I also tried with following options (i’m not sure is this valid way to add options to db url?):

DATABASE_URL='mysql://57d19a8h5xauk6bbn3s3:************@aws.connect.psdb.cloud:3306/xnonxix?serverVersion=8.0&ssl={"rejectUnauthorized":false}&sslaccept=strict'

And this:

DATABASE_URL='mysql://57d19a8h5xauk6bbn3s3:************@aws.connect.psdb.cloud:3306/xnonxix?serverVersion=8.0&ssl={"rejectUnauthorized":false}&sslcert=/etc/ssl/certs/ca-certificates.crt'

Unfortunately, nothing works.

If this can help there is my fly.toml:

app = "xnonxix"
primary_region = "lhr"

[build]
  [build.args]
    NODE_VERSION = "20"
    PHP_VERSION = "8.2"
    SYMFONY_APP_ENV = "prod"

[env]
  SYMFONY_APP_ENV = "prod"
  
[http_service]
  internal_port = 8080
  force_https = true
  auto_stop_machines = true
  auto_start_machines = true
  min_machines_running = 0
  processes = ["app"]

[deploy]
  command = "bin/console doctrine:migrations:migrate --no-interaction"

Does anyone know what solve a problem? I’m not sure is the problem in my server setup, Symfony or PlanetScale?

Meanwhile I found solution, the problem was with my Symfony configuration.

Here is solution in case someone has the same problem:

You need to add MYSQL_ATTR_SSL_CA option to config/packages/doctrine.yaml:

doctrine:
    dbal:
        url: "%env(resolve:DATABASE_URL)%"
        options:
            !php/const:PDO::MYSQL_ATTR_SSL_CA: '%env(DATABASE_SSL_CA_PATH)%'

And then create env variable as DATABASE_SSL_CA_PATH=“/etc/ssl/certs/ca-certificates.crt”. That is correct path for fly.io (at least for my setup), could be different on different setups though.

I found solution here MySQL + SSL + Doctrine

I also found that there php package to handle this automatically (if you don’t know path of certification, it will find it automatically): Zero-Configuration SSL CA root bundles in Doctrine DBAL with Symfony | Colin O'Dell. I didn’t test does it work, above solution was easier for me.

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