Search code examples
phplaravellocalhost

How do I successfully serve a local Laravel app on my phone without the connection refused error?


I'm running a Laravel 9 app on my MacBook using php artisan serve. I would like to see the app on my Android phone, but I'm failing.

Both the computer and the phone are connected to the same WiFi network. I serve the app on my computer and access its public IP:port on my phone, like this:

HTTP://192.168.1.10:8000

However, all I'm getting is an error in Chrome: Err_Connection_Refused. Tried Firefox as well.

What might be wrong or missing here?


Solution

  • The full artisan command for running a Laravel application that you want reached from other devices is

    sudo php artisan serve --host 192.168.1.10 --port 8080
    

    This opens up listening to the external port of 8080 for incoming traffic from outside localhost or 127.0.0.1