Folks,
The Internet is full of hits on this topic, but none really helps or the information is very outdated.
I want to establish a TLS-secured connection to a mySQL database server using PHP 7.4.
I want to avoid client certificates - if possible - because they are "over engineered" for my use case.
Unfortunately, I only manage to establish an unsecured connection. As soon I enforce only secure connections (require-secure-transport = on
), the external Webserver is not able to connect to the DB.
With this configuration, the authentication will fail. I thought, filling $mysqli->ssl_set
with NULL
will initiate a TLS-Connection.
Any idea how to solve this?
mySQL-Server Configuration:
Creating Certs
mkdir /etc/mysql/certs
sudo openssl genrsa -out /etc/mysql/certs/ca-key.pem 4096
sudo openssl req -new -x509 -nodes -days 1825 -key /etc/mysql/certs/ca-key.pem -out
/etc/mysql/certs/ca-cert.pem
chown -R mysql:mysql /etc/mysql/certs/
DB-Setup /etc/mysql/mariadb.conf.d/50-server.cnf
[mysql]
general_log_file = /var/log/mysql/mysql.log
general_log = 1
log_error = /var/log/mysql/error.log
ssl_cert = /etc/mysql/certs/ca-cert.pem
ssl_key = /etc/mysql/certs/ca-key.pem
tls_version = TLSv1.2,TLSv1.3
require-secure-transport = on
bind-address = 0.0.0.0 # will allow Connections from everywhere
PHP
/var/www/html/example.php
$servername = "foo.bar";
$username = "user";
$password = "secret";
$dbname = "myDb";
$mysqli = mysqli_init();
$mysqli->ssl_set(NULL, NULL, NULL, NULL, NULL);
$mysqli->real_connect($servername, $username, $password, $dbname);