Skip to content

Commit dff0d33

Browse files
lacpandorejaviereguiluz
authored andcommitted
Update doctrine.rst on ssl documentation
1 parent 68ca943 commit dff0d33

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

reference/configuration/doctrine.rst

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,5 +470,62 @@ If the ``dir`` configuration is set and the ``is_bundle`` configuration
470470
is ``true``, the DoctrineBundle will prefix the ``dir`` configuration with
471471
the path of the bundle.
472472

473+
SSL Connection with MySQL
474+
~~~~~~~~~~~~~~~~~~~~~~~~~
475+
476+
If you want to configure a secure SSL connection to MySQL in your Symfony application using Doctrine, you need to set specific options for the SSL certificates. Here's how to configure the connection using environment variables for the certificate paths:
477+
478+
.. configuration-block::
479+
480+
.. code-block:: yaml
481+
482+
doctrine:
483+
dbal:
484+
url: '%env(DATABASE_URL)%'
485+
server_version: '8.0.31'
486+
driver: 'pdo_mysql'
487+
options:
488+
# SSL private key (PDO::MYSQL_ATTR_SSL_KEY)
489+
1007: '%env(MYSQL_SSL_KEY)%'
490+
# SSL certificate (PDO::MYSQL_ATTR_SSL_CERT)
491+
1008: '%env(MYSQL_SSL_CERT)%'
492+
# SSL CA authority (PDO::MYSQL_ATTR_SSL_CA)
493+
1009: '%env(MYSQL_SSL_CA)%'
494+
495+
.. code-block:: xml
496+
497+
<?xml version="1.0" encoding="UTF-8" ?>
498+
<container xmlns="http://symfony.com/schema/dic/services"
499+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
500+
xmlns:doctrine="http://symfony.com/schema/dic/doctrine"
501+
xsi:schemaLocation="http://symfony.com/schema/dic/services
502+
https://symfony.com/schema/dic/services/services-1.0.xsd
503+
http://symfony.com/schema/dic/doctrine
504+
https://symfony.com/schema/dic/doctrine/doctrine-1.0.xsd">
505+
506+
<doctrine:config>
507+
<doctrine:dbal
508+
url="%env(DATABASE_URL)%"
509+
server-version="8.0.31"
510+
driver="pdo_mysql">
511+
512+
<doctrine:option key="1007">%env(MYSQL_SSL_KEY)%</doctrine:option>
513+
<doctrine:option key="1008">%env(MYSQL_SSL_CERT)%</doctrine:option>
514+
<doctrine:option key="1009">%env(MYSQL_SSL_CA)%</doctrine:option>
515+
</doctrine:dbal>
516+
</doctrine:config>
517+
</container>
518+
519+
Make sure that your environment variables are correctly set in your ``.env.local`` or ``.env.local.php`` file as follows:
520+
521+
.. code-block:: bash
522+
523+
MYSQL_SSL_KEY=/path/to/your/server-key.pem
524+
MYSQL_SSL_CERT=/path/to/your/server-cert.pem
525+
MYSQL_SSL_CA=/path/to/your/ca-cert.pem
526+
527+
This configuration secures your MySQL connection with SSL by specifying the paths to the required certificates.
528+
529+
473530
.. _DBAL documentation: https://www.doctrine-project.org/projects/doctrine-dbal/en/current/reference/configuration.html
474531
.. _`Doctrine Metadata Drivers`: https://www.doctrine-project.org/projects/doctrine-orm/en/current/reference/metadata-drivers.html

0 commit comments

Comments
 (0)