AWS Lightsail WordPress – connect to database on instance using mysqli

//Params to connect to a database
$dbHost = "*static ip of wordpress site*";

This should be $dbHost = "localhost"; instead, or "127.0.0.1" (or even "::1").

localhost uses a separate virtual network interface that makes sure traffic between services on your Linux VM doesn’t leave the VM In general it’s safer to use localhost rather than other IPs that belong to host interfaces because

  • you’ll avoid any problems with firewalls that might be configured on the host
  • ditto in an AWS environment you’ll avoid any security group / VPC filters, if e.g. you were using the public facing IP as your host rather than the internal IP address on the virtual private cloud which is different
  • mysql logins can be filtered by the hosts they’re allowed to connect from, and if your root user may be restricted to localhost logins at the database level.