php artisan serve starts but the app is not reachable, or the .env is ignored
php artisan serve runs but the browser cannot open the site from another device or from DockerShort answer
php artisan serve listens on 127.0.0.1 port 8000 by default. If a port you passed is busy it will not move on by itself, and from another device or a container nothing reaches 127.0.0.1. Shell variables are also dropped when a .env file exists. Check host, port and variables first.
Fix it fast
1Find out which cause you have
Run the server in the foreground and read its output. Then check who already listens on port 8000.
php artisan serve lsof -nP -iTCP:8000 -sTCP:LISTEN2Match what you see, then jump to its fix
- 1
The command exits instead of starting, and you gave --port or set SERVER_PORTThe port you passed is already in useFix - 2
It works in the browser on the same computer but not from a phone, a VM or a Docker hostThe server listens on 127.0.0.1, so other machines cannot reach itFix - 3
A variable you export before php artisan serve does not appear in env() inside the appShell variables are not passed on because a .env file existsFix - 4
Only creating a single server.PHP_CLI_SERVER_WORKERS is set above 1Fix
- 1
What does the error look like?
php artisan serve runs but the browser cannot open the site from another device or from DockerServer stops right after start with a non-zero exit code when --port is given and the port is busyOnly creating a single server.A variable exported in the shell has no effect inside the app
Cause 1 of 4
The port you passed is already in use
1Check
The command only moves to the next port by itself when you did not pass --port. With an explicit port it gives up after the PHP server fails.
lsof -nP -iTCP:8000 -sTCP:LISTEN2Fix
Stop the other process, or choose a free port.
php artisan serve --port=80013Verify
The command prints the new address and stays running.
curl -I http://127.0.0.1:8001Confirmed by raw.githubusercontent.com
Cause 2 of 4
The server listens on 127.0.0.1, so other machines cannot reach it
1Check
The default host is 127.0.0.1 unless SERVER_HOST is set. That address only accepts connections from the same machine.
php artisan serve --help2Fix
Bind to all interfaces for local testing only, then open the machine's LAN address.
php artisan serve --host=0.0.0.0 --port=80003Verify
Open http://<your-lan-ip>:8000 from the other device.
curl -I http://<your-lan-ip>:8000Confirmed by raw.githubusercontent.com
Cause 3 of 4
Shell variables are not passed on because a .env file exists
1Check
When a .env file exists and --no-reload is not used, the command forwards only a short list of variables (APP_ENV, PATH, XDEBUG_* and a few others) and sets the rest to false. Variables you want must be in .env.
grep -n 'MY_VARIABLE' .env2Fix
Put the value in .env, or start the server with --no-reload so the full environment is passed through.
php artisan serve --no-reload3Verify
Print the value from inside the app.
php artisan tinker
>>> env('MY_VARIABLE')Confirmed by raw.githubusercontent.com
Cause 4 of 4
PHP_CLI_SERVER_WORKERS is set above 1
1Check
A value above 1 needs --no-reload. Without it the command warns and runs a single server.
echo $PHP_CLI_SERVER_WORKERS2Fix
Either unset the variable, or add --no-reload when you really want several workers.
PHP_CLI_SERVER_WORKERS=4 php artisan serve --no-reload3Verify
The warning no longer appears.
php artisan serve --no-reloadConfirmed by raw.githubusercontent.com
How do I stop it coming back?
- Pick one dev port per project and write it into SERVER_PORT in .env.
- Use 0.0.0.0 only on a trusted network; it exposes the dev server to everyone on it.
- Keep configuration in .env instead of exporting variables in the shell.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- Spotless LaundryAn on-demand laundry app: Flutter on a Laravel back end, with Firebase for live updates.
- EZ EstimaterConstruction quoting and job tracking for contractors, on a Laravel and Firebase stack.
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
Related fixes
Back end
composer require laravel/horizon fails: ext-pcntl is missing
laravel/horizon v1.1.0 requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system
Horizon needs the pcntl extension, and Composer refuses to install it where PHP lacks that extension.
3 causes, each with a fixBack end
Guzzle or Http::get fails with cURL error 6 in Laravel
Illuminate\Http\Client\ConnectionException: cURL error 6: Could not resolve host
cURL error 6 means the machine running PHP could not turn the host name in the URL into an IP address.
3 causes, each with a fixBack end
Laravel cannot find the database host: getaddrinfo failed
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for mysql failed
The message means PHP could not turn DB_HOST into an IP address.
3 causes, each with a fixBack end
Composer says the gd extension is missing on a Laravel project
composer install or composer update stops on a package that requires ext-gd
Composer refuses to install a package that requires ext-gd when the PHP binary running Composer has no GD extension.
4 causes, each with a fixBack end
composer require maatwebsite/excel fails to install
Composer says the package needs an older PHP than the one installed
Composer refuses maatwebsite/excel when the PHP version or a PHP extension does not match what the package and PhpSpreadsheet need.
3 causes, each with a fixBack end
composer install says the lock file is not compatible and asks for update
Your lock file does not contain a compatible set of packages. Please run composer update.
composer install checked the locked packages against this machine's PHP and extensions and found a conflict.
3 causes, each with a fix