2

I'm working on a project where I have to use SSL to connect to the MySQL database. This is working in vanilla PHP, but not when I try to use Laravel.

Working PHP-code:

<?php
$host = 'xxx';
$db = 'xxx';
$user = 'xxx';
$pass = 'xxx';
$charset = 'utf8';

$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
$options = [
    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
    PDO::ATTR_EMULATE_PREPARES => false,
    PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => false,
    PDO::MYSQL_ATTR_SSL_CA => "../rootCA.pem",
];

try {
    $pdo = new PDO($dsn, $user, $pass, $options);
} catch (\PDOException $e) {
    throw new \PDOException($e->getMessage(), (int)$e->getCode());
}

$data = $pdo->query('SELECT * FROM x LIMIT 100')->fetchAll(PDO::FETCH_ASSOC);
var_export($data);

But when I try to connect via Laravel, then i get the following error:

C:\*\*\vendor\laravel\framework\src\Illuminate\Database\Connection.php on line 330
[Fri Sep 14 11:35:05 2018] ::1:54869 [500]: /data - Allowed memory size of 134217728 bytes exhausted (tried to allocate 4096 bytes) in C:\*\*\vendor\laravel\framework\src\Illuminate\Database\Connection.php on line 330

My Laravel (5.7) config for the connection:

    'mysql' => [
        'driver' => 'mysql',
        'host' => env('DB_HOST', 'xxx'),
        'port' => env('DB_PORT', 'xxx'),
        'database' => env('DB_DATABASE', 'xxx'),
        'username' => env('DB_USERNAME', 'xxx'),
        'password' => env('DB_PASSWORD', ''),
        'unix_socket' => env('DB_SOCKET', ''),
        'charset' => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix' => '',
        'strict' => false,
        'engine' => null,
        'options' => array(
            PDO::MYSQL_ATTR_SSL_CA  => '../rootCA.pem',
            PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => false
        ),
    ],

Any ideas? =)

2 Answers 2

3

You need to provide full path of files.

'options' => [
    PDO::MYSQL_ATTR_SSL_KEY => base_path('ssl/client-key.pem'),
    PDO::MYSQL_ATTR_SSL_CERT => base_path('ssl/client-cert.pem'),
    PDO::MYSQL_ATTR_SSL_CA => base_path('ssl/ca-cert.pem')
]

Please see link: How do I connect to a MySQL database over SSL with Laravel 5.3

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your answer, I did try this as well, unfortunately with the same result.
Hello @Tibbelit, Please change memory_limit in php.ini. Like ; Old Limit ; memory_limit = 512M ; New Limit memory_limit = 2048M
Did try to change it to "-1" as well, didn't help :/ VirtualAlloc() failed: [0x00000008] Not enough storage is available to process this command. VirtualFree() failed: [0x000001e7] Attempt to access invalid address. VirtualAlloc() failed: [0x00000008] Not enough storage is available to process this command. [Fri Sep 14 13:49:08 2018] ::1:57501 [500]: /data - Out of memory (allocated 838860800) (tried to allocate 4096 bytes) in C:\Projects*\vendor\laravel\framework\src\Illuminate\Database\Connection.php on line 330
1

The problem was not with the connectcion it self. It was that I tried to fetch to many rows from my SQL-query which (really strange) gave me error messages like:

SSL operation failed with code 1. OpenSSL Error messages: error:1408F10B:SSL routines:ssl3_get_record:wrong version number

etc. So my bad - but I was hoping that the error messages could have been better.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.