Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing to laravel server from android phone at a port

Trying to access to laravel server at localhost:8000 from android phone. What I did:

  • Laptop & android phone is connected to same router.
  • started laravel server at localhost at port 8000
  • find out my laptop's ip for the router i.e. 192.168.0.110
  • from phone browser tried to visit 192.168.0.110:8000

If I visit 192.168.0.110 then I can see the default page from php server. But when trying to connect to that port - shows error page saying:

This site can't be reached

In my laptop's browser I can visit localhost:8000

What's wrong I am doing? or what to do to connect?

For more OS:: Linux Mint and firewall (ufw) is turned off.

Update Couldn't solve the issue. Using ngrok instead. ngrok creates a publicly shareable url tunnelled to your localhost:port.

like image 500
Shafi Avatar asked Sep 11 '17 09:09

Shafi


People also ask

How can I access laravel site from another network?

If you are on Linux or Mac, type ifconfig at the terminal. If you are on Windows, type ipconfig at the command prompt. If you'd also like to pass the port parameter, just add --port=XX to the artisan serve command. And voila!

How do I serve a laravel project on a different port?

We can run the laravel project using "php artisan serve" command. It will use by default 8000 port to run the laravel app. But you want to run laravel project on a different port then the artisan command provides an option called "--port" and you can run the laravel app in a different port.


2 Answers

Type this in laravel application command line

php artisan serve --host 0.0.0.0

like image 117
arya praza musabbih Avatar answered Sep 26 '22 00:09

arya praza musabbih


I encountered the same challenge when i was developing a barcode verification app. This was my solution:

I ran the following code so as to be able to use my system IP to access the laravel server

php artisan serve --host 0.0.0.0

After running the code, I was able to access my laravel server from both my browser and android app through links like:

http://192.168.0.160/barcode/public/checker

or

http://192.168.0.160:8000/checker/

Also don't forget to include this in your manifest file:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
like image 43
ABODE Avatar answered Sep 27 '22 00:09

ABODE