Skip to content

Commit 36cc247

Browse files
author
lacpandore
committed
Update doctrine.rst on ssl documentation
1 parent 8dc3c89 commit 36cc247

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
@@ -466,5 +466,62 @@ If the ``dir`` configuration is set and the ``is_bundle`` configuration
466466
is ``true``, the DoctrineBundle will prefix the ``dir`` configuration with
467467
the path of the bundle.
468468

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

0 commit comments

Comments
 (0)