1

I am trying to set up my CakePHP 3.8 project on a GCP "Compute Engine" VM.

I have set up my app.php to use the following DB configuration:

'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
'persistent' => false,
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'username' => 'user',
'password' => 'password',
'database' => 'dbname',
'prefix' => '',
'encoding' => 'utf8',
'timezone' => 'UTC',
'cacheMetadata' => true,
'log' => false,
'flags' => [
    PDO::MYSQL_ATTR_INIT_COMMAND => "SET @@SESSION.sql_mode='';",
    // uncomment below for use with Google Cloud SQL
    PDO::MYSQL_ATTR_SSL_KEY  => CONFIG.'ssl/client-key.pem',
    PDO::MYSQL_ATTR_SSL_CERT => CONFIG.'ssl/client-cert.pem',
    PDO::MYSQL_ATTR_SSL_CA   => CONFIG.'ssl/server-ca.pem',
    PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => false
],
'cacheMetadata' => true,
'log' => false,

My problem happens when I try to run migrations. The site works just fine with the above configuration, however, if I run

$> php bin/cake.php migrations migrate

I get a slew of errors saying that it cannot connect, access denied for user@host.

If I add

'ssl_key' => CONFIG .'ssl/client-key.pem',
'ssl_cert' => CONFIG . 'ssl/client-cert.pem',
'ssl_ca' => CONFIG . 'ssl/server-ca.pem',

I get an error:

Caused by: [PDOException] PDO::__construct(): Peer certificate CN=`gcpname:gcpserver' did not match expected CN=`111.111.111.111' in /var/www/mydomain.com/vendor/robmorgan/phinx/src/Phinx/Db/Adapter/PdoAdapter.php on line 79

ndm
  • 59,784
  • 9
  • 71
  • 110
user4838338
  • 83
  • 1
  • 5

1 Answers1

1

I guess this is because the migrations plugin still doesn't pass the flags or custom mysql_attr_* options over to the Phinx connection configuration, see this issue:

https://github.com/cakephp/migrations/issues/374

I don't think there's much that can be done here, other than adding support for flags / attribute options, or using Phinx directly (ie without the Migrations plugin).

I've pushed a PR that would add support for driver specific flags, you might want to give it a try and comment on the issue or the PR whether it works for you (it's for CakePHP 4.x (Migrations 3.x), I'll backport it for CakePHP 3.x (Migrations 2.x) in case it's being accepted):

https://github.com/cakephp/migrations/pull/478

ndm
  • 59,784
  • 9
  • 71
  • 110