1

My mobile app uses an API from a url say example.com.

However I want it to use my local development version that's on my machine which is example.dev.

I set this up on my machine by adding the following to my routes file:

192.168.10.10 example.dev 

The ip: 192.168.10.10 directs to a VM (more specifically Laravel's Homestead).

This means when I type example.dev on my desktop web browser, it directs me to the VM.

I want it so that when I type example.dev on my mobile browser, it will also direct me to the VM on my desktop.

Note that both the mobile phone and desktop are on the same network.

Progress so far

After going through loads of SO answers I have found the followinG;

  • I can use my local IP address (e.g. 192.168.0.50) to access my localhost. However, I want to access the VM, not localhost!
  • Use vagrant share, but this just creates a 400 Bad request error, which apparently is still an open issue!
  • Add the local ip to the map attribute on homestead.yaml. However I can only access the website like this: 192.168.0.50:8000. Also not sure how I can add more sites using this approach?
Yahya Uddin
  • 26,997
  • 35
  • 140
  • 231
  • See https://stackoverflow.com/q/43397630/470749 and https://stackoverflow.com/a/41857012/470749 and vote for them if they're helpful. – Ryan Aug 28 '17 at 03:48

2 Answers2

2

i only had to edit the Homestead.yaml like this:

ip: 192.168.10.10
memory: 2048
cpus: 2
provider: virtualbox
ssl: true
authorize: ~/.ssh/id_rsa.pub
keys:
    - ~/.ssh/id_rsa
folders:
    -   map: 'C:\Users\Patata\Documents\code'
        to: /home/vagrant/code
sites:
    -   map: homestead.test
        to: /home/vagrant/code/laravel/ComunicacionesApp/public
    -   map: phpmyadmin.test
        to: /home/vagrant/code/sites/phpmyadmin
networks:
    - type: "public_network"
      ip: "192.168.0.100"
databases:
    - homestead
features:
    -   mariadb: false
    -   ohmyzsh: false
    -   webdriver: false
name: code
hostname: code

I only had to add this piece of code:

networks:
    - type: "public_network"
      ip: "192.168.0.100"

192.168.0.100 is an available ip on my router list, save Homestead.yaml, and then, write on your phone's browser: 192.168.0.100 to test, and that's all.

My network adapter is in default NAT configuration. Source: https://laravel.com/docs/5.4/homestead#network-interfaces

0

If you are using NAT in VMWare workstation then add a port forwarding to the Virtual Network editor. This will direct 192.168.0.50:80 to your VM using port 80.

  • Open Virtual network editor (may need to run as administrator), click on the NAT selection in Network Type
  • Click "NAT Settings"
  • Click "Add" Under Port forwarding
  • Put the port you want forwarded from your host machine (ie: 80)
  • Put in your VM's NAT IP address (use IPconfig for windows while in the VM)
  • Add the port you need it to open or forward to on your VM (IE: 80)
  • Give it a name and click OK.
  • Click OK on the NAT settings page, Then OK or Apply and try now with your VM network Connection set to NAT.
LazySmerf
  • 11
  • 2
  • Unfortunately, I am not using VMWare workstation. I am using homestead (which uses vagrant and VirtualBox). – Yahya Uddin Jan 25 '17 at 17:12
  • Are you using a NAT network connection or a bridged connection? Bridged should be pretty simple just use your HOST file to point to the Guest IP if you hosting the web address on your host. Or just set the webaddress to the guest IP. Just some thoughts. – LazySmerf Jan 25 '17 at 18:23