Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.3] Bind serve cmd to 127.0.0.1 instead of localhost #16937

Merged
merged 1 commit into from
Dec 23, 2016
Merged

[5.3] Bind serve cmd to 127.0.0.1 instead of localhost #16937

merged 1 commit into from
Dec 23, 2016

Conversation

fideloper
Copy link
Contributor

@fideloper fideloper commented Dec 22, 2016

On latest Mac (Sierra) and perhaps earlier, localhost is using the ipv6 network.

This creates behavior like the following:

php artisan serve --port=8181

# Works
curl localhost:8181

# Fails: Connection refused
curl 127.0.0.1:8181

# Works
curl "http://[::1]:8181"

This is probably a confusing error for those hitting it when using 127.0.0.1.

We can make sure we bind to ipv4 by either binding to 0.0.0.0 or 127.0.0.1. Binding to 127.0.0.1 is safer of course, and doesn't really change expected behavior (since ipv6 is not prevalent still and we're just talking localhost networks here).

This change would behave like this:

# If 127.0.0.1 would be the new default, we wouldn't need to define it:
php artisan serve --host=127.0.0.1 --port=8181

# Works
curl localhost:8181

# Works
curl 127.0.0.1:8181

# Fails (and anyone using this address would presumably 
# have a good reason for doing so, right?)
curl "http://[::1]:8181"

Other OS considerations:

  1. Windows: localhost often checks ipv6 first and then goes to ipv4 if nothings listening on v6. This creates considerable lag, so using 127.0.0.1 may work better on Windows as well
  2. Linux: I don't believe this is default behavior on even newer versions of Linux, but since we're talking about localhost networks in any case, I don't see any reason not to assume ipv4 over ipv6 would be the expected localhost network to use

On latest Mac (Sierra) and perhaps earlier, `localhost` is using the ipv6 network.

This creates behavior like the following:

```bash
php artisan serve --port=8181

# Works
curl localhost

# Fails: Connection refused
curl 127.0.0.1

# Works
curl "http://[::1]:8181"
```

This is probably a confusing error for those hitting it when using `127.0.0.1`.

We can make sure we bind to ipv4 by either binding to `0.0.0.0` or `127.0.0.1`.  Binding to `127.0.0.1` is safer of course, and doesn't really change expected behavior (since ipv6 is not prevalent still and we're just talking localhost networks here).

This change would behave like this:

```bash
# If 127.0.0.1 is the default, we don't need to define it,
# but just so you can see it in its current form:
php artisan serve --host=127.0.0.1 --port=8181

# Works
curl localhost

# Works
curl 127.0.0.1

# Fails (and anyone using this address would presumably 
# have a good reason for doing so, right?)
curl "http://[::1]:8181"
```

Other OS considerations:

1. Windows: localhost often checks ipv6 first and then goes to ipv4 if nothings listening on v6. This creates considerable lag, so using 127.0.0.1 may work better on Windows as well
2. Linux: I don't believe this is default behavior on even newer versions of Linux, but since we're talking about localhost networks in any case, I don't see any reason not to assume ipv4 over ipv6 would be the expected localhost network to use
@fideloper fideloper changed the title Bind serve cmd to 127.0.0.1 instead of localhost [5.3] Bind serve cmd to 127.0.0.1 instead of localhost Dec 22, 2016
@taylorotwell taylorotwell merged commit f9ed425 into laravel:5.3 Dec 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants