Php mysql ssl connection does not work

I recently got an ssl certificate and tried to refactor my PHP code into working over this secure connection.

require './credentials.php';

    $conn = mysqli_init();
    if (!$conn){
        die("Init error");
    }

    $conn -> ssl_set("key.pem", "cert.pem", NULL, NULL, NULL);

    if(!$conn -> real_connect($servername, $username, $password, $dbname . 'feed')){
        die("Connect error:" . mysqli_connect_error());
    }

It returns Connect error:MySQL server has gone away

What should I do? Is openssl enabled?

This is an interesting error, one which I haven’t seen before. OpenSSL is enabled, but I don’t think that is causing the issue.

After reading about this error, I can see that the error your encountering is the SQL Server timing out, most likely due to invalid SSL.

Reading about the MySQL ssl_set function, you are missing one of the required parameters (The CA Cert). Most likely, because this is missing, a secure connection cannot be made.

2 Likes

Our database servers don’t support SSL. They are only accessible to the internal network which we control, so there isn’t really a need to secure this connection.

OpenSSL is enabled so you can connect with a MySQL database over SSL as far as I know. Just not our MySQL databases.

The “SSL support” we offer is related to use HTTPS to secure the connection between the browsers of the visitors of your website and the server your website runs on.

5 Likes

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.