Shafi
Shafi

Reputation: 1970

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:

If I visit 192.168.0.110 then the default page from php server loads. But when trying to connect to that port (8000 for this example) - shows error page saying:

This site can't be reached

In laptop's browser I can visit localhost:8000

What's wrong am I doing?

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.

Upvotes: 6

Views: 7811

Answers (4)

jasjastone
jasjastone

Reputation: 149

if you want to serve to the application; please follow the following procedures

  1. Connect your phone and your computer on the same network, if you sing a wifi network, or a router or even if you serve your computer with your mobile wifi run this command

for linux

ifconfig | grep "inet " | grep -v 127.0.0.1

Result Example

inet 192.168.250.1 netmask 255.255.255.0 broadcast 0.0.0.0 inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255 inet 192.168.43.210 netmask 255.255.255.0 broadcast 192.168.43.255

for windows

ipconfig Result Use the IP4 Adress is the ip of your computer

  1. Then take the ip address of your computer the serve your project with a ip by specify the host

php artisan serve --host=<Your Computer Ip Address>

  1. now you can take your phone an open the phone browser then access the application using the ip of the computer and the port number that was used when you run php artisan serve Example http://192.168.43.210:8000

if you don't want to specify the port number when visit the application on your phone use the following command php artisan serve --host=<Your Computer Ip> --port=80 Then when visit the application on your phone use only the ip address of your computer without the port number Example http://192.168.43.210 NOTE: On linux system you may have to use sudo in order to use this command sudo php artisan serve --host=192.168.43.210 --port=80

Reference Link Laracast How to access laravel website in phone

Upvotes: 1

ABODE
ABODE

Reputation: 1018

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" />

Upvotes: 8

arya praza musabbih
arya praza musabbih

Reputation: 91

Type this in laravel application command line

php artisan serve --host 0.0.0.0

Upvotes: 9

Omkar
Omkar

Reputation: 3100

instead of localhost:8080 use
10.0.0.2:8000
this url.

Upvotes: 0

Related Questions