I've setup a MariaDB version 10.3 to use PAM to authenticate it's users by simply running on the server (while connected to the database as root):
MariaDB [(none)]> INSTALL SONAME 'auth_pam';
After that, I've created a database user using PAM as it's autentication method:
MariaDB [(none)]> CREATE USER 'casafamilia'@'localhost' IDENTIFIED VIA pam;
I can connect to the database using the local mysql client just fine, so the PAM module is working:
# mysql -u casafamilia -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 68
Server version: 10.3.17-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
But when using PHP + mysqli, I get the following error:
# php db_mysqli.php
PHP Warning: mysqli::__construct(): The server requested authentication method unknown to the client [dialog] in /root/db_mysqli.php on line 7
PHP Warning: mysqli::__construct(): (HY000/2054): The server requested authentication method unknown to the client in /root/db_mysqli.php on line 7
Connection failed: The server requested authentication method unknown to the client
Here is the simple PHP code to connect to the database:
<?php
$servername = "localhost";
$username = "casafamilia";
$password = "<thepassword>";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
PHP Version:
# php --version
PHP 7.2.24 (cli) (built: Oct 24 2019 19:36:00) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.24, Copyright (c) 1999-2018, by Zend Technologies
How do I connect my PHP application to MariaDB when using PAM to autenticate database users?