I used to connect to my database over SSL by directly modifying the createDbConnection method in Craft's AppBehavior.php:
$dbConnection = new DbConnection();
$dbConnection->connectionString = $this->_processConnectionString();
$dbConnection->emulatePrepare = true;
$dbConnection->username = craft()->config->get('user', ConfigFile::Db);
$dbConnection->password = craft()->config->get('password', ConfigFile::Db);
$dbConnection->charset = craft()->config->get('charset', ConfigFile::Db);
$dbConnection->tablePrefix = $dbConnection->getNormalizedTablePrefix();
$dbConnection->driverMap = array('mysql' => 'Craft\MysqlSchema');
// additional attributes to connect over SSL
if (getenv('DB_SSL_ENABLED') == 'true')
{
$dbConnection->attributes = array(
PDO::MYSQL_ATTR_SSL_CIPHER => 'DHE-RSA-AES256-SHA:AES128-SHA',
PDO::MYSQL_ATTR_SSL_CA => CRAFT_CONFIG_PATH . 'rds-combined-ca-bundle.pem',
);
}
$dbConnection->init();
But as of a new Craft release there is a native Craft way to do this by setting a new "attributes" key in the database config file. Unfortunately, Craft won't make a connection when I connect using this new method. I get the dreaded Craft can’t connect to the database with the credentials in craft/config/db.php error. My revised db.php looks like this:
$url = parse_url(getenv("DATABASE_URL"));
define(SERVER, $url["host"]);
define(USER, $url["user"]);
define(PASSWORD, $url["pass"]);
define(DATABASE, substr($url["path"], 1));
return array(
'server' => SERVER,
'user' => USER,
'password' => PASSWORD,
'database' => DATABASE,
'tablePrefix' => 'craft',
'attributes' => array(
PDO::MYSQL_ATTR_SSL_CIPHER => 'DHE-RSA-AES256-SHA:AES128-SHA',
PDO::MYSQL_ATTR_SSL_CA => CRAFT_CONFIG_PATH . 'rds-combined-ca-bundle.pem',
)
);
Not sure what could be going wrong here. Are there additional attributes that need to be set when doing this the Yii way?
$dbConnection->attributes
just like you're doing: github.com/pixelandtonic/Craft-Release/blob/master/app/etc/…\PDO::
work?