Fixing SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed

Sqlstate error usually happens when there is a problem connecting to the database, you can troubleshoot this by checking the connectivity from the source web-server to the database and the firewall rules if it's on a different server than the web server.

Ping the database

ping server-name

If you are not getting a reply or it's not resolving then maybe you need to check the dns or hosts file to be sure that it's pointed to the right ip

Check the firewall and if the port is opened between both server

nmap -sS -O server_name or IP_Address

Use nmap to check firewall status

You should see something like:

3306/tcp open mysql

Or different ports and service if it's ms-sql, if the port is not there or closed, then you need to open the firewall.

 


Subscribe to
for video tutorials updates