Symfony : how to set SSL parameters in Doctrine DBAL configuration (YAML)?

后端 未结 6 1870
误落风尘
误落风尘 2021-02-09 10:56

I\'d like to add my SSL cert and key files to Doctrine DBAL configuration but I don\'t see how to achieve that.

In PHP, I just have to write something like :

<         


        
6条回答
  •  遥遥无期
    2021-02-09 11:07

    I found a much easier way than the rest. Make the following settings in app/config/config.yml:

    # Doctrine Configuration
    doctrine:
        dbal:
            driver:   pdo_mysql
            host:     "%database_host%"
            port:     "%database_port%"
            dbname:   "%database_name%"
            user:     "%database_user%"
            password: "%database_password%"
            charset:  UTF8
            # Options for SSL connection
            options:
                MYSQL_ATTR_SSL_CA : %ca_cert%
                MYSQL_ATTR_SSL_KEY : %private_key%
                MYSQL_ATTR_SSL_CERT : %public_cert%
    

    Then in your app/config/parameters.yml file:

    parameters:
        ...
        # SSL Info
        private_key: /etc/my.cnf.d/certs/client-key.pem
        public_cert: /etc/my.cnf.d/certs/client-cert.pem
        ca_cert: /etc/my.cnf.d/certs/ca-cert.pem
    

    I tested this on Symfony3 and this works great. The paths above may be different, in particular the certs may be different depending on your distro and how you set it up.

提交回复
热议问题