|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77482 Wont bind to IPv4 if IPv6 enabled
Submitted: 2019-01-17 19:34 UTC Modified: 2019-01-25 04:37 UTC
Avg. Score:4.2 ± 1.0
Reproduced:4 of 4 (100.0%)
Same Version:2 (50.0%)
Same OS:3 (75.0%)
From: php at darkain dot com Assigned:
Status: Open Package: FPM related
PHP Version: 7.2 OS: FreeBSD
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: php at darkain dot com
New email:
PHP Version: OS:


 [2019-01-17 19:34 UTC] php at darkain dot com
1) Create a bare FreeBSD jail
2) Inside of jail, run "pkg install php73"
3) Change /usr/local/etc/php-fpm.d/www.conf to "listen = 9000"
4) Run "service php-fpm onestart" to start the PHP FPM daemon

PHP service is now running, but only listening on IPv6:9000, not IPv4:9000.

Expected result:
Listening on both IPv4 and IPv6

Actual result:
root@php-test:~ # sockstat -l
www      php-fpm    37643 5  tcp6   *:9000                *:*
www      php-fpm    37642 5  tcp6   *:9000                *:*
root     php-fpm    37641 7  tcp6   *:9000                *:*

(note the pack of tcp4 in PROTO)


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-01-17 19:44 UTC] php at darkain dot com
Changing listen to "" will properly listen on IPv4 without IPv6 as expected. Manually specifying an IP address (either v4 or v6) works as expected as well. It is only when specifying port ONLY that it is broken according to the docs.
 [2019-01-22 17:27 UTC] laszlo at karolyi dot hu
+1, Same as #77501.

Adding the information here that listening on both interfaces is only available with specifying two separate fpm configurations, with the respective listen directives.
 [2019-01-25 04:32 UTC] ard_1 at mail dot ru
This bug affects PHP version 7.2.14 as well.
The jail is not required to reproduce this problem - PHP installations without a jail are also affected.
The corresponding FreeBSD bug on this issue:
 [2019-01-25 04:37 UTC]
-PHP Version: 7.3.1 +PHP Version: 7.2
 [2019-01-25 05:56 UTC] ard_1 at mail dot ru
Looking at the fpm_socket.c code and the comments in it I can see that some incorrect assumptions are being made.
The current code is performing the following steps to bind to the TCP socket:
		/* Bind ANYADDR
		 * Try "::" first as that covers IPv6 ANYADDR and mapped IPv4 ANYADDR
		 * silencing warnings since failure is an option
		 * If that fails (because AF_INET6 is unsupported) retry with
As far is I know IPv4 mapped addresses are disabled by default in FreeBSD, also if IPv6 support is enabled in the kernel (which is enabled by default in GENERIC kernel) than there always be at least one IPv6 interface - it is lo0 (localhost). That leads to the AF_INET6 is reported as being supported and the code will not fail to bind to IPv6 ANYADDR. So there would be no attempt to bind to IPv4 ANYADDR.
 [2019-01-25 07:31 UTC] ard_1 at mail dot ru
This bug should also hit OpenBSD users since as far as I know there is no support for IPv4 mapped addresses exist in OpenBSD at all.

Also if I'm getting the root cause of this problem right, setting sysctl net.ipv6.bindv6only=1 in Linux should perform a similar effect and PHP-FPM would not bind to IPv4 ANYADDR too.
 [2019-01-25 08:11 UTC] ard_1 at mail dot ru
This non-portable socket binding behavior was brought with the attempt to fix bug and a corresponding commit.

As far as I know, the portable way to fix this bug is possible by creating two independent sockets. PHP-FPM should bind to IPv6 socket with setsockopt() to turn on the IPV6_V6ONLY option. And then it should try to bind an IPv4 socket to the same port on
 [2023-06-13 08:26 UTC] worldtalkn at gmail dot com
World Talk News are sharing latest news about home improvement, auto, tech, business, travel, health, entertainment, real estate etc. More info to visit: (
 [2023-06-21 16:12 UTC] laszlo at karolyi dot hu
4 years later, this bug still exists in PHP 8.2.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 18 04:01:34 2024 UTC