2

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?

Rodrigo Renie
  • 99
  • 1
  • 3
  • 3
    Did you try the following server option in my.cnf: pam_use_cleartext_plugin = ON ? – Georg Richter Nov 18 '19 at 04:36
  • 2
    Why do you close this question by pointing to an answer which handles a different problem? The problem is that the server requests a dialog plugin, which is not available in mysqli/mysqlnd - so server needs to be reconfigured to use cleartext plugin. – Georg Richter Nov 18 '19 at 19:44
  • 1
    @GeorgRichter thank you, that option actually solved my problem. I don't know why the moderator closed this topic marking it as duplicate when it clearly is not. I'm not sure what I can do about it. – Rodrigo Renie Nov 20 '19 at 01:47

0 Answers0