php artisan serve --host 0.0.0.0 can't be accessed from mobile device on same network

php artisan serve --host 0.0.0.0 can't be accessed from mobile device on same network

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

php artisan serve Network Binding and Localhost Confusion

When you run php artisan serve --host 192.168.X.XXX, you are instructing PHP's built-in server to listen specifically on that IP address. While this command appears correct for exposing a service over a local network, the inability to reach it from other devices—even those on the same Wi-Fi—usually points to a fundamental misunderstanding of how the development server binds interfaces or how your operating system handles incoming connections.

The primary failure mode occurs when the application is hosted behind a reverse proxy like Nginx or Apache. If you have configured these proxies with proxy_pass directives pointing to http://127.0.0.1:8000 or http://localhost:8000, and then attempt to access the site via the public IP (e.g., http://192.168.X.XXX/), the request arrives at your server's external interface. The web server forwards this request internally to the PHP artisan process. However, the development server is configured to listen only on localhost (127.0.0.1) or a specific private IP that might not be fully compatible with the internal loopback logic of the proxy depending on the OS network stack configuration. This creates a scenario where the request never successfully resolves to the listening socket, resulting in connection timeouts rather than HTTP errors.

To resolve this without relying on php artisan serve --host 0.0.0.0 (which is often discouraged for production-like setups due to lack of security features), you must ensure the development server is binding to the correct interface or configure your proxy correctly. The most robust solution involves switching the PHP artisan host to 0.0.0.0. This tells the server to accept connections on any available network interface, including the specific IP address assigned to your Wi-Fi adapter.

php artisan serve --host=0.0.0.0 --port=8000

When using 0.0.0.0, ensure that your firewall allows incoming traffic on port 8000. On macOS, you can verify this by checking the "Firewall" settings in System Preferences or running sudo pfctl -s info to inspect packet filter status. If the firewall is blocking the port, you will see connection refused errors from other devices even if the application is running correctly.

Alternatively, if you are strictly using a reverse proxy, update your Nginx configuration to pass requests to the IP address of the host machine rather than the loopback address. For example:

location / {
    proxy_pass http://192.168.X.XXX:8000;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

Here, 192.168.X.XXX should match the IP address you identified as your Mac's local network interface. Using localhost in the proxy_pass directive when the development server is not bound to localhost will cause the proxy to send the request to 127.0.0.1, which might be ignored if the OS prioritizes external interfaces for that specific binding context.

Another common pitfall involves Docker environments. If you are running Laravel inside a container, php artisan serve binds only to the container's internal network stack. Accessing it from the host machine or other devices requires exposing the port explicitly in your docker-compose.yml:

services:
  laravel:
    build: .
    ports:
      - "8000:8000"
    volumes:
      - .:/var/www/html
    working_dir: /var/www/html

Without the port mapping, the container listens on 0.0.0.0 internally, but no traffic reaches the host's network interface.

If you need to deploy this setup in a production environment, consider using Laravel Forge or Envoyer, which handle deployment and load balancing more securely. For advanced hosting scenarios, you can explore the solutions provided by https://laravelcompany.com to integrate with their infrastructure for streamlined management. Ultimately, verifying that your firewall permits inbound connections and ensuring your reverse proxy points to the correct external IP are the critical steps to making your local development environment accessible across a network.

Our network