Symfony:如何在Doctrine DBAL配置(YAML)中设置SSL参数? [英] Symfony : how to set SSL parameters in Doctrine DBAL configuration (YAML)?
问题描述
我想将我的SSL证书和密钥文件添加到Doctrine DBAL配置中,但是我不知道如何实现.
I'd like to add my SSL cert and key files to Doctrine DBAL configuration but I don't see how to achieve that.
在PHP中,我只需要编写如下内容:
In PHP, I just have to write something like :
$databaseHandler = new \PDO(
'mysql:host=my_host;dbname=my_db',
'username',
'password',
array(
\PDO::MYSQL_ATTR_SSL_KEY => '.../client-key.pem',
\PDO::MYSQL_ATTR_SSL_CERT => '.../client-cert.pem',
\PDO::MYSQL_ATTR_SSL_CA => '.../ca-cert.pem'
)
);
我了解有一个自定义驱动程序选项 driverOptions
,我看到了此答案但我不确定如何将其转换为YAML.
I understand there is a Custom Driver Option driverOptions
, and I saw this answer but I'm not sure about how to translate that into YAML.
我觉得我应该写一些接近的东西:
I have the feeling I should write something close to :
doctrine:
dbal:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
driverOptions:
PDO::MYSQL_ATTR_SSL_CA: '.../client-key.pem'
PDO::MYSQL_ATTR_SSL_CERT: '.../client-cert.pem'
PDO::MYSQL_ATTR_SSL_CA: '.../ca-cert.pem'
但是双冒号不会真的让YAML满意...
But double colons won't really please YAML...
推荐答案
我发现了一种比其他方法简单得多的方法.
在app/config/config.yml
中进行以下设置:
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%
然后在您的app/config/parameters.yml
文件中:
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
我在Symfony3上进行了测试,效果很好.上面的路径可能不同,尤其是证书可能会有所不同,具体取决于您的发行版和设置方式.
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.
这篇关于Symfony:如何在Doctrine DBAL配置(YAML)中设置SSL参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!