Warning: mysqli_connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known

Warning: mysqli_connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Warning: mysqli_connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known

The error message mysqli_connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known is a classic symptom of a DNS resolution failure within your PHP application. It tells you that the database client cannot translate the hostname you provided into an IP address, or it cannot reach the port specified. While the source material shows a PDOException regarding "Connection refused" after switching to PDO, the underlying issue with mysqli_connect is almost always the same: the connection parameters are incorrect for your specific environment.

In the provided code snippet using Cloud9, you are attempting to connect to a host named paralphdigm-vtms-2622120. This string looks like an internal hostname or a specific server identifier. If this name does not exist in the DNS records of the machine running your PHP script (likely an Ubuntu instance within Cloud9), the system's resolver library will fail immediately with getaddrinfo failed: Name or service not known.

Environment Mismatch and Hostnames

The most common cause for this error when moving code between environments is assuming that a database server address defined in one environment works in another. Local development setups often use localhost or 127.0.0.1, while cloud hosts might require specific private subnets or public endpoints.

In your Cloud9 workspace, the file path /home/ubuntu/workspace/db.php suggests you are running PHP on a Linux VM. If the database server is hosted externally or in a different network segment, the hostname paralphdigm-vtms-2622120 must be resolvable from that specific Ubuntu instance. If you copied this configuration from a local machine where that hostname was valid (perhaps via /etc/hosts), it will fail immediately on the cloud host because the external DNS does not know what paralphdigm-vtms-2622120 maps to.

To verify this, log into your Cloud9 terminal and run:

ping parallphdigm-vtms-2622120
# or
getent hosts parallphdigm-vtms-2622120

If these commands return "unknown host" or fail to resolve an IP, the mysqli_connect error is guaranteed. You must ensure that the database hostname points to a server reachable from your application's network context. If the database is on the same Cloud9 instance, use localhost instead of that complex hostname.

Port Configuration and Connection Refused

Your second error, SQLSTATE[HY000] [2002] Connection refused, usually indicates that DNS resolution succeeded (or the error was suppressed), but the TCP handshake failed. This often happens when the default port 3306 is not open or the connection is being blocked by a firewall.

In Cloud9 environments, you might be connecting to a database that is restricted to specific IP addresses. If your application tries to connect from a public IP range to a database that only accepts connections from its own internal network, the server will actively drop the connection, resulting in "Connection refused."

When switching between mysqli and PDO, ensure consistency in how you handle hostnames. The PDO DSN string mysql:host=$dbhost;dbname=$dbname behaves identically to mysqli_connect() regarding hostname resolution. If the hostname is invalid, PDO will throw a different exception message initially, but if the environment doesn't report it immediately, it might look like a connection timeout or refusal later in the handshake process.

Security and Credential Handling

Another critical aspect of your configuration is the database password. In the source code provided:

$dbpass="";

An empty password combined with an incorrect hostname can sometimes mask other errors if the server allows null authentication but fails to connect due to network issues. However, leaving passwords empty in production code is a significant security risk. If you are using this for local development within Cloud9, ensure that your .env file or configuration manager is handling sensitive data securely rather than hardcoding strings directly into the source file.

If you are integrating this logic into a Laravel application, consider using Laravel's database configuration files which support environment-specific variables. This approach prevents accidental deployment of empty passwords or incorrect hostnames to production servers. You can find more information on securing your application stack and managing configurations at https://laravelcompany.com.

Troubleshooting Steps

To resolve the getaddrinfo failed error specifically:

  1. Verify DNS: Ensure the hostname resolves from the server executing PHP. Update /etc/hosts on the Cloud9 instance if the database is in the same cloud network but not exposed via public DNS.
  2. Check Firewall Rules: If you have access to the database server, ensure that port 3306 is bound to the correct interface and not restricted to 127.0.0.1 only if you are connecting remotely.
  3. Simplify the Hostname: Unless using a specific managed service endpoint, try connecting via IP address directly to rule out DNS misconfiguration.

By ensuring that the hostname is resolvable from the application server and that the network path to the database port is open, you can eliminate both the getaddrinfo failure and the subsequent connection refusal errors.

Our network