How do I connect to a MySQL database over SSL with Laravel 5.3

后端 未结 3 1917
难免孤独
难免孤独 2020-12-20 08:38

I\'ve been searching all over the internet and haven\'t had any success.

eg: https://laravel.io/forum/06-18-2014-connecting-mysql-over-ssl?page=1 https://laracasts

相关标签:
3条回答
  • 2020-12-20 08:50

    Ok. Solved the issue. Hopped on the phone with microsoft and noticed one of the log errors was:

    PDO::__construct(): Peer certificate CN=`resourceregion-a.control.database.windows.net' did not match expected CN=`db.mysql.database.azure.com'
    

    And that line in the documentation that @alexejenko points out, the bit after that:

    " If you require to use "--ssl-mode=VERIFY_IDENTITY", then you can ping your server name to resolve the regional server name, such as westeurope1-a.control.database.windows.net, and use that regional server name in the connection until this issue is resolved. We plan to remove this limitation in the future."

    Turns out this is what was happening. The database connection was routing to the regional database, not mine. So yay for not quite finished products.

    Once I changed my DB_HOST to that region it successfully connected (note: make sure you've whitelisted your ips).

    0 讨论(0)
  • 2020-12-20 09:00

    Sometimes, the same error is displayed when you don't have permissions for access remotely to the database.

    example here:

    • Server1-app: 123.123.123.12
    • Server2-database: 456.456.456.45

    So, you can try from Server1-app:

    $ mysql -u youruser -h yourpassword;
    

    And into mysql terminal, check if you are able to access to the database:

    $ show databases;
    

    If your database is shown, you have privileges and everything is ok, if not, you must acces to your Server2-database and grant privileges to your user.

    Once in Server2-database;

    $ mysql -u root -p
    $ GRANT ALL PRIVILEGES ON your_database.* TO 'youruser'@'123.123.123.12';
    $ FLUSH PRIVILEGES;
    $ exit;
    

    Hope it be helpful;

    0 讨论(0)
  • 2020-12-20 09:14

    You need to provide the full path to the files. If they're in your laravel application folder then you can use the base_path method to generate the full poth. You may also need to define the cert and ca.

    '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')
    ]
    
    0 讨论(0)
提交回复
热议问题