Skip to content
MtrXTools

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

  1. Check the host value in your .env or config; newer PHP versions name it in the error.
  2. Resolve the name from the same machine or container: getent hosts db.
  3. Use 127.0.0.1 for a database on the same machine, or the Docker service name inside the same network.
Look up the name

Got a different message? Paste it into the error explainer.

Related errors

All 32 Languages & runtimes errors