@@ -466,5 +466,84 @@ If the ``dir`` configuration is set and the ``is_bundle`` configuration
466466is ``true ``, the DoctrineBundle will prefix the ``dir `` configuration with
467467the path of the bundle.
468468
469+ SSL Connection with MySQL
470+ ~~~~~~~~~~~~~~~~~~~~~~~~~
471+
472+ To securely configure an SSL connection to MySQL in your Symfony application
473+ with Doctrine, you need to specify the SSL certificate options. Here's how to
474+ set up the connection using environment variables for the certificate paths:
475+
476+ .. configuration-block ::
477+
478+ .. code-block :: yaml
479+
480+ doctrine :
481+ dbal :
482+ url : ' %env(DATABASE_URL)%'
483+ server_version : ' 8.0.31'
484+ driver : ' pdo_mysql'
485+ options :
486+ # SSL private key (PDO::MYSQL_ATTR_SSL_KEY)
487+ 1007 : ' %env(MYSQL_SSL_KEY)%'
488+ # SSL certificate (PDO::MYSQL_ATTR_SSL_CERT)
489+ 1008 : ' %env(MYSQL_SSL_CERT)%'
490+ # SSL CA authority (PDO::MYSQL_ATTR_SSL_CA)
491+ 1009 : ' %env(MYSQL_SSL_CA)%'
492+
493+ .. code-block :: xml
494+
495+ <?xml version =" 1.0" encoding =" UTF-8" ?>
496+ <container xmlns =" http://symfony.com/schema/dic/services"
497+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
498+ xmlns : doctrine =" http://symfony.com/schema/dic/doctrine"
499+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
500+ https://symfony.com/schema/dic/services/services-1.0.xsd
501+ http://symfony.com/schema/dic/doctrine
502+ https://symfony.com/schema/dic/doctrine/doctrine-1.0.xsd" >
503+
504+ <doctrine : config >
505+ <doctrine : dbal
506+ url =" %env(DATABASE_URL)%"
507+ server-version =" 8.0.31"
508+ driver =" pdo_mysql" >
509+
510+ <doctrine : option key =" 1007" >%env(MYSQL_SSL_KEY)%</doctrine : option >
511+ <doctrine : option key =" 1008" >%env(MYSQL_SSL_CERT)%</doctrine : option >
512+ <doctrine : option key =" 1009" >%env(MYSQL_SSL_CA)%</doctrine : option >
513+ </doctrine : dbal >
514+ </doctrine : config >
515+ </container >
516+
517+ .. code-block :: php
518+
519+ // config/packages/doctrine.php
520+ use Symfony\Config\DoctrineConfig;
521+
522+ return static function (DoctrineConfig $doctrine): void {
523+ $doctrine->dbal()
524+ ->connection('default')
525+ ->url(env('DATABASE_URL')->resolve())
526+ ->serverVersion('8.0.31')
527+ ->driver('pdo_mysql');
528+
529+ $doctrine->dbal()->defaultConnection('default');
530+
531+ $doctrine->dbal()->option(\PDO::MYSQL_ATTR_SSL_KEY, '%env(MYSQL_SSL_KEY)%');
532+ $doctrine->dbal()->option(\PDO::MYSQL_SSL_CERT, '%env(MYSQL_ATTR_SSL_CERT)%');
533+ $doctrine->dbal()->option(\PDO::MYSQL_SSL_CA, '%env(MYSQL_ATTR_SSL_CA)%');
534+ };
535+
536+ Ensure your environment variables are correctly set in the ``.env.local `` or
537+ ``.env.local.php `` file as follows:
538+
539+ .. code-block :: bash
540+
541+ MYSQL_SSL_KEY=/path/to/your/server-key.pem
542+ MYSQL_SSL_CERT=/path/to/your/server-cert.pem
543+ MYSQL_SSL_CA=/path/to/your/ca-cert.pem
544+
545+ This configuration secures your MySQL connection with SSL by specifying the paths to the required certificates.
546+
547+
469548.. _DBAL documentation : https://www.doctrine-project.org/projects/doctrine-dbal/en/current/reference/configuration.html
470549.. _`Doctrine Metadata Drivers` : https://www.doctrine-project.org/projects/doctrine-orm/en/current/reference/metadata-drivers.html
0 commit comments