1

SSL 経由で MySQL データベースに接続しようとしましたが、次のコマンド ラインを使用して、ssh 経由で Web サーバーからの接続を正常に確立しました。

mysql -h my.host.here --port=5454  -v --ssl-ca=/etc/apache2/ssl/mysql/ca-cert.pem --ssl-cert=/etc/apache2/ssl/mysql/client-cert.pem --ssl-key=/etc/apache2/ssl/mysql/client-key.pem -u user -p

ただし、symfony2 と doctrine で同じ接続を設定しようとすると、「SSL エラー」しか表示されません。

    $params = array(
        'driver'   => 'pdo_mysql',
        'user'     => 'user',
        'password' => 'pass',
        'host'     => 'my.host.here',
        'dbname'   => 'media',
        'port'     => '5454',
    );

    if($this->container->hasParameter('media_ca') && $this->container->hasParameter('media_cert') && $this->container->hasParameter('media_key')) {
        $params['driverOptions'] = array(
            PDO::MYSQL_ATTR_SSL_CA => $this->container->hasParameter('media_ca'),
            PDO::MYSQL_ATTR_SSL_CERT => $this->container->hasParameter('media_cert'),
            PDO::MYSQL_ATTR_SSL_KEY => $this->container->hasParameter('media_key'),
        );
    }

/* Using this instead with only the ca_cert gives me the same error
    if($this->container->hasParameter('media_ca')) {
        $params['driverOptions'] = array(
            PDO::MYSQL_ATTR_SSL_CA => $this->container->hasParameter('media_ca'),
        );
    }
*/
    $connectionFactory = $this->container->get('doctrine.dbal.connection_factory');
    $conn = $connectionFactory->createConnection($params);
    return $conn;

私のログでは:

[2013-10-01 15:23:30] request.CRITICAL: Uncaught PHP Exception PDOException: "SQLSTATE[HY000] [2026] SSL connection error" at /var/www/mysite/vendor/doctrine/dbal/lib/Doctrine /DBAL/Driver/PDOConnection.php 行 36 {"例外":"[オブジェクト] (PDOException: SQLSTATE[HY000] [2026] /var/www/mysite/vendor/doctrine/dbal/lib/Doctrine/ での SSL 接続エラーDBAL/Driver/PDOConnection.php:36)"} []

Web サーバーのユーザー (www-data) が証明書ファイルにアクセスできること、およびそれらの証明書ファイルへのパスが正しいこと (symfony2 パラメーターで定義) を再確認しました。

コマンドライン接続と doctrine/symfony2 で指定した接続との違いは他に思い浮かびません。

4

2 に答える 2

1

パラメータの取得に誤りがあります。getParameter($param)の代わりにメソッドが必要ですhasParameter($param)。これらの行は正しいです。

PDO::MYSQL_ATTR_SSL_CA => $this->container->getParameter('media_ca'),
PDO::MYSQL_ATTR_SSL_CERT => $this->container->getParameter('media_cert'),
PDO::MYSQL_ATTR_SSL_KEY => $this->container->getParameter('media_key'),
于 2013-10-01T14:43:39.333 に答える
1

完全な例を記録するために、私が最終的に問題を解決した方法を記録します。

//Create a connection to another public database.
 private function videoDatabase() {

    //Create a connection to pub-DB.

    $params = array(
        'driver'   => $this->container->getParameter('media_database_driver'),
        'user'     => $this->container->getParameter('media_database_user'),
        'password' => $this->container->getParameter('media_database_password'),
        'host'     => $this->container->getParameter('media_database_host'),
        'dbname'   => $this->container->getParameter('media_database_name'),
        'port'     => $this->container->getParameter('media_database_port')
    );

    if($this->container->hasParameter('media_ca') && $this->container->hasParameter('media_cert') && $this->container->hasParameter('media_key')) {
       $params['driverOptions'] = array(
                PDO::MYSQL_ATTR_SSL_CA => $this->container->getParameter('media_ca'),
                PDO::MYSQL_ATTR_SSL_CERT => $this->container->getParameter('media_cert'),
                PDO::MYSQL_ATTR_SSL_KEY => $this->container->getParameter('media_key'),
        );
   }

    $connectionFactory = $this->container->get('doctrine.dbal.connection_factory');
    $conn = $connectionFactory->createConnection($params);
    return $conn;

 }
于 2013-10-21T11:22:56.960 に答える