php_network_getaddresses: getaddrinfo failed
PHP couldn't resolve the hostname
Seen in PHP (PDO, mysqli, fsockopen, file_get_contents), Laravel, WordPress
PHP could not resolve the hostname it was given, so the database or HTTP connection was never attempted.
Common causes
- A wrong host in config, such as DB_HOST set to a Docker service name when PHP runs outside Docker, or the reverse.
- A typo, or a URL with scheme passed where only a host is expected.
- The server has no working DNS ("Temporary failure in name resolution").
How to fix it
- Check the host value in your .env or config; newer PHP versions name it in the error.
- Resolve the name from the same machine or container: getent hosts db.
- Use 127.0.0.1 for a database on the same machine, or the Docker service name inside the same network.
Got a different message? Paste it into the error explainer.
Related errors
- socket.gaierror: [Errno -2] Name or service not known · Python couldn't resolve the hostname
- socket.gaierror: [Errno -3] Temporary failure in name resolution · Python couldn't reach a DNS resolver
- java.net.UnknownHostException · Java couldn't resolve the hostname
- dial tcp: lookup example.com: no such host · Go couldn't resolve the hostname
- No such host is known · Windows couldn't resolve the hostname
- [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed · Python couldn't verify the server's certificate
- certificate verify failed: Hostname mismatch, certificate is not valid for · The certificate doesn't cover this hostname
- Max retries exceeded with url · requests gave up connecting to the URL
- requests.exceptions.ConnectTimeout · Python couldn't open the connection in time
- requests.exceptions.ReadTimeout · The server took too long to respond
- ConnectionRefusedError: [Errno 111] Connection refused · Nothing is listening on that port
- http.client.RemoteDisconnected: Remote end closed connection without response · The server closed the connection without replying