0

I'm trying to create a connection to a local Database Server through a VPN connection first.

From the VPN connection I receive this IP for my network: 192.168.30.2

DB-Server: 192.168.40.150

If I try to ping the DB Server IP via PHP, I also get a response from the Server. When, however, I try to make the PDO connection or with "mysqli", I receive the following error:

lluminate \ Database \ QueryException: SQLSTATE [HY000] [1045] Access denied for user 'xxxx'@'192.168.30.2' (using password: YES) (SQL: select * from `xxxx`) in file

If I use a Mysql Client from my PC it's working fine!

Any idea?

Mirko Pira
  • 13
  • 2
  • does the user in mysql accept connection from 192.168.30.2 ? ('xxxx'@'%') ? – SmasherHell Apr 27 '20 at 08:22
  • Check this https://stackoverflow.com/a/59813485/12232340 and this https://stackoverflow.com/a/58234430/12232340 –  Apr 27 '20 at 08:25
  • @SmasherHell if I use a mysql client software on my local machine works fine. IP is: 192.168.30.2 – Mirko Pira Apr 27 '20 at 08:37
  • @Dlk configuration seems OK. I tried to debug the PDO Connection and the Host is: 192.168.40.150. I dont understand because the PDO Connectore use the IP Address from VPN ('xxxx'@'192.168.30.2') – Mirko Pira Apr 27 '20 at 08:40
  • I am not laravel person. but that sounds like you need to include port into connection ? –  Apr 27 '20 at 08:42
  • From what you tell, there is only two causes : the mysql user does not accept your host, but if your other client work fine locally, I think you may have a typo in your user/password. The message from the server is clearly "I can not authenticate you" – SmasherHell Apr 27 '20 at 09:50
  • FOUND: SSL Connection was required! These PDO options are needed: PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => false, PDO::MYSQL_ATTR_SSL_CA => '' Other Problem: my Laravel "database.php" config doesn't read these options. – Mirko Pira Apr 27 '20 at 11:12

1 Answers1

1

SOLVED: the DB server required a SSL Connection (without Cert). These options was required in the PDO connection:

  • PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT
  • PDO::MYSQL_ATTR_SSL_CA

If you use Laravel Illuminate for the connection you need to declerate the options in the connection, example:

...
        'options' => extension_loaded('pdo_mysql') ? array_filter([
            PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => env('MY_SSL_VERIFY', ' '),
            PDO::MYSQL_ATTR_SSL_CA => env('MY_SSL_CA', ' '),
        ]) : [],
...

In this case is really important to give a Value with empty space ' ' otherwise will the Illuminate PDO Connector not get the option values.

Mirko Pira
  • 13
  • 2