PHP MySQL over SSL. Peer certificate did not match

前端 未结 5 2016
死守一世寂寞
死守一世寂寞 2020-12-25 13:56

I\'m trying to use Google Cloud SQL over SSL from GCE(Google Compute Engine) instance. My problem is that I cannot connect to Cloud SQL instance over SSL.

mysql comm

5条回答
  •  旧时难觅i
    2020-12-25 14:20

    For mysqli, adding:

    MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT
    

    to real_connect() solved my instance of this issue.

    Example (replace host, user, password and database as needed):

    $db_connection->real_connect('ip address or host', 'user', 'password', 'database', 3306, NULL, MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT);
    

    Full php mysqli SSL connection script:

    // check if openssl is enabled on server
    if(!extension_loaded('openssl')) {
        throw new Exception('This app needs the Open SSL PHP extension and it is missing.');
    }
    
    // start connection
    $db_connection = mysqli_init(); 
    
    // set ssl config (update with your certs location)
    $db_connection->ssl_set('/etc/my.cnf.d/certs/client-key.pem','/etc/my.cnf.d/certs/client-cert.pem', '/etc/my.cnf.d/certs/ca-cert.pem', NULL, NULL); 
    
    // connect (update with your host, db and credentials)
    $db_connection->real_connect('ip address or host', 'user', 'password', 'database', 3306, NULL, MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT);
    

提交回复
热议问题