8

I'm having an issue with my local laravel server. I'm building an API, and I need to test from another device, but the only url which is working is:

localhost:8000

If I try

127.0.0.1:8000

or using my machine local IP

192.168.0.6:8000

I have a ERR_CONNECTION_REFUSED from chrome (I tried with safari too). There is no 'blocking' extensions

enter image description here enter image description here

Daniel Campos
  • 971
  • 4
  • 11
  • 20

5 Answers5

26

I found the answer: artisan serve isolates the host, so if I want to specify it, I need to do:

php artisan serve --host=127.0.0.1
Daniel Campos
  • 971
  • 4
  • 11
  • 20
  • That's very usefull. I have deployed a laravel api and used your solution changing 127.0.0.1 for the public IP of the hosted server. And finally works! :) – Wal Heredia Jun 25 '19 at 13:47
  • @Daniel Campos: What do you mean by "isolates the host" can you explain in proper details, also how can I force override it or make artisan not isolate localhost, that way I may be able to use localhost for more than one php.exe instances ? – Vicky Dev Oct 20 '21 at 18:51
  • This work perfectly, i used it with my machine's ip 192.168.1.142 so i could access the API from my phone. – RandomUsername Jan 30 '23 at 21:04
1

Depending on what project you may in! In our case we had a bought project! And https is configured by default! So https://..../app.css will not be accessible!

When you visit the link again in chrome it switch to http://.../app.css and it will work!

For our bought base code an env variable was setup and i just disabled it as bellow: enter image description here

You may like to disable it in development!

This link may be helpful too!

How to force Laravel Project to use HTTPS for all routes?

Otherwise you can setup https to work well! Check how to do that with apache! Or nginx !

Otherwise know that you can't do it with php artisan serve! And you'll need to disable force https!

See the option bellow! (check the first answer to see if you can still use php artisan serve! And read the second one! To get why php artisan serve doesn't support https)

Laravel php artisan serve to mimic HTTPS

I hope this may help some! That fall on the same problem! Which is a line of things to check to add to the list here!

Mohamed Allal
  • 17,920
  • 5
  • 94
  • 97
0

php artisan serve :

Laravel development server started on http://localhost:8000/

so you can only access to this server by http://localhost:8000/

loic.lopez
  • 2,013
  • 2
  • 21
  • 42
0

I had that problem because I forgot to execute npm run devto launch Vite server.

zm455
  • 489
  • 11
  • 26
-2

Open up the terminal window in your working directory and run

php artisan serve

You will then be able to access your laravel local development through your browser by using the URL http://localhost:8000

Paradigm
  • 371
  • 2
  • 12