Commit 43d34e27d2c for php
commit 43d34e27d2c611806708de8ed5fd0863f22d5d5c
Author: Jakub Zelenka <bukka@php.net>
Date: Sun Nov 29 22:13:19 2026 +0100
Fix hostname resolution after DNS test resolver setup (#25905)
The new GitHub runner images do not have the hostname in /etc/hosts and
rely on systemd-resolved synthesizing it. Once /etc/resolv.conf points to
the BIND test server the hostname no longer resolves, which breaks sudo
and the slapd certificate setup. Add the hostname to /etc/hosts when it is
not resolvable and remove it again in resolv-reset.sh.
diff --git a/ext/standard/tests/dns/common.sh b/ext/standard/tests/dns/common.sh
index 32b6080ac94..360970a962a 100755
--- a/ext/standard/tests/dns/common.sh
+++ b/ext/standard/tests/dns/common.sh
@@ -9,6 +9,8 @@ DNS_PORT="${PHP_DNS_TEST_PORT:-53}"
RESOLV_CONF="/etc/resolv.conf"
RESOLV_CONF_BACKUP="/etc/resolv.conf.php-dns-test.orig"
+HOSTS_FILE="/etc/hosts"
+HOSTS_MARK="# php-dns-test"
AA_PROFILE="/etc/apparmor.d/usr.sbin.named"
diff --git a/ext/standard/tests/dns/resolv-reset.sh b/ext/standard/tests/dns/resolv-reset.sh
index 5a4be74648b..b531e332fb2 100755
--- a/ext/standard/tests/dns/resolv-reset.sh
+++ b/ext/standard/tests/dns/resolv-reset.sh
@@ -20,4 +20,6 @@ else
rm -f "$RESOLV_CONF_BACKUP"
fi
+sed -i "/ $HOSTS_MARK\$/d" "$HOSTS_FILE"
+
echo "$RESOLV_CONF restored"
diff --git a/ext/standard/tests/dns/resolv-setup.sh b/ext/standard/tests/dns/resolv-setup.sh
index e72357459a5..608423b309e 100755
--- a/ext/standard/tests/dns/resolv-setup.sh
+++ b/ext/standard/tests/dns/resolv-setup.sh
@@ -31,3 +31,10 @@ chmod 644 "$RESOLV_CONF"
echo "$RESOLV_CONF now contains:"
cat "$RESOLV_CONF"
+
+# systemd-resolved synthesizes the local hostname, without it the name must be in /etc/hosts
+host="$(hostname)"
+if [[ -n "$host" ]] && ! getent hosts "$host" >/dev/null; then
+ echo "127.0.1.1 $host $HOSTS_MARK" >> "$HOSTS_FILE"
+ echo "$host added to $HOSTS_FILE"
+fi