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

Commits on Dec 22, 2016

  1. Bind serve cmd to 127.0.0.1 instead of localhost

    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 authored Dec 22, 2016
    Configuration menu
    Copy the full SHA
    3da06cb View commit details
    Browse the repository at this point in the history