0

hope you are all good,

I 'am working on a react native app for android, and i need data from my laravel API, the route works fine when i test it with Postman but on my mobile app i got an Error : Network Error.

I have been told that is because i need to put my laravel project on https so i tried

php artisan serve --port=443

but i got this error

Failed to listen on 127.0.0.1:443 (reason: Permission denied).

i'am really stuck and i don't know where the problem is...

Thank you all for you help mates

VLAZ
  • 26,331
  • 9
  • 49
  • 67
Mishimaster
  • 144
  • 1
  • 2
  • 9

1 Answers1

2

You've got a bunch of misconceptions interacting with each other here.

Misconception: Running on port 443 will give you HTTPS

Your attempted solution is to make your server listen on port 443, which is the default port for HTTPS.

It is failing because you are running the server as a user that doesn't have permission to listen on that port.

While you could solve that by running with admin privileges, that will just mean you are running an HTTP server on the default HTTPS port. Anything connecting to https://127.0.0.1/ will get an error because it will try to establish an encrypted connection and the HTTP server will be confused.

As far as I can tell, Artisan doesn't support HTTPS directly and you have to use a proxy server instead.

If you were to go down that route, then you could run both Artisan and the HTTPS proxy on any port. You can port a port number in an https:// URL just as you can with an http:// URL.

Misconception: You need HTTPS

You're getting a Network Error error when you try to connect from the mobile app.

While there are some things which require HTTPS, just loading a web page isn't one of them, and the things that do generally are quite explicit about requiring HTTPS in their error logs.

The real cause is most likely because the server is listening on 127.0.0.1localhost. It isn't accessible from a different computer.

Solutions

Listen on a different Network interface

You can listen on a non-privileged port on a LAN-facing IP address and then any device on your LAN can connect to it.

php artisan serve --host 192.168.1.101 --port 8000

Make sure you replace the host with an IP address belonging to your computer!

Use a proxy

A service like ngrok will expose your local (listening only on localhost) service on the public Internet (tunneling through any NAT on your router if needed) making it accessible to just about any device.

It can wrap it in HTTPS at the same time if you like.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335