For me the issue was DNS. I was using AWS RDS for database, ping responded ok, dig responded ok, I could telnet to it.
Then I tried using PhpMyAdmin and it responded with
mysqli_real_connect(): php_network_getaddresses: getaddrinfo failed: No address associated with hostname
Wordpress didn’t show this error, I couldn’t find it in any logs.
I added RDS IP into /etc/hosts file and that solved the issue in WordPress.
No idea why PHP had issue resolving RDS hostname.