Recently I have subscribed to Digital Ocean managed database and I was facing this issue where I was not able to connect to the database. I got the following error.
Error: Connection failed: The server requested authentication method unknown to the client
The reason was that Nginx configuration was using php 7.0 even though php -v
command shows the output as 7.2
My droplet config:
Ubuntu 16.04
PHP 7.2
MySQL 5.7
So to change the default php version, I am using Nginx so I ran the following command.
update-alternatives --set php /usr/bin/php7.2
service nginx restart
If you are using apache, you can use the following commands
a2enmod php7.2
service apache2 restart
Still, when I echo the output of phpinfo()
it shows that my website was using php7.0
Next, I decided to check the Nginx config file for any issues. To my surprise it was set to use php7.0
I changed to Nginx config to the following.
...
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}
...
After that restarted the service and I was able to connect to the database.
sudo systemctl restart nginx
More information regarding this issue can be found here. https://www.php.net/manual/en/mysqli.requirements.php