Reputation: 1970
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
Reputation: 149
if you want to serve to the application; please follow the following procedures
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
php artisan serve --host=<Your Computer Ip Address>
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 Examplehttp://192.168.43.210
NOTE: On linux system you may have to use sudo in order to use this commandsudo php artisan serve --host=192.168.43.210 --port=80
Reference Link Laracast How to access laravel website in phone
Upvotes: 1
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
Reputation: 91
Type this in laravel application command
line
php artisan serve --host 0.0.0.0
Upvotes: 9