1
votes

I have Laravel Homestead running on my computer just fine where projects are run locally using 'localhost:8000' in my web browser. Now I want to run projects using my computer's IP Address but I'm having issues accomplishing this task. I've tried a couple of different methods such as using XAMPP but I'm having trouble using that as well.

Here is what I have up and running along with the applications that are being used:

  1. Laravel Homestead which uses VirtualBox, Vagrant and Composer.
  2. I use 'cmd' to start the VirtualBox using 'Vagrant Status' & 'Vagrant Up' respectively.
  3. PuTTY for connecting to my VirtualBox using 'vagrant' as the login and my password.
  4. After successfully logging in using PuTTY, I use the 'composer' commands for creating projects and the respective Laravel PHP commands for performing migrations 'php artisan migrate', 'php artisan dump-autoload' etc.

Here is my Homestead.yaml configuration:

---
ip: "192.168.10.10"
memory: 2048
cpus: 1

authorize: C:/Users/Jeff/.ssh/id_rsa.pub

keys:
   - C:/Users/Jeff/.ssh/id_rsa

folders:
   - map: C:/Users/Jeff/Desktop/Code
    to: /home/vagrant/Code

 sites:
   - map: homestead.app
    to: /home/vagrant/Code/laravel-photo-gallery-build3/public


 variables:
  - key: APP_ENV
    value: local 

Is there an easy way to map my Laravel Homestead projects using my computer's IP address? Any help will be greatly appreciated!

1
Is there a reason you want to use the IP address rather than mapping to a specific site domain name? like myprojectname.app?Chris Schmitz

1 Answers

2
votes

There may be a specific reason that you want to use our computer's IP address that I'm not aware of, but if it's just because of how you developed in the past I would suggest against it. Unless you have a static IP address for your computer your IP address is going to eventually change which will break your setup.

What I would suggest is using your domain mapping in the Homestead file instead.

sites:
   - map: homestead.app
     to: /home/vagrant/Code/laravel-photo-gallery-build3/public

What's happening here is the yaml file is telling the virtual machine "hey, whenever you see the domain homestead.app, redirect to this particular folder".

After you add that mapping you can then modify your hosts file to point browser requests for homestead.app to your local machine (instead of our on the web). In your hosts file, add the following line at the bottom:

127.0.0.1 homestead.app

I'm not super familiar with where windows puts all of it's files, but it looks like you can find the hosts file in:

C:\Windows\System32\Drivers\etc\hosts

Once you've modified both your hosts file and your yaml file, restart your vagrant machine and force it to provision:

vagrant reload --provision

After that you should be able to open a browser and go to the url to view your site:

homestead.app:8000

Also, you can rename the homestead.app portion to whatever domain you want to show your site as. Just be sure you don't name it the same name as an actual site online, otherwise you'll never be able to get to the online version (because your computer will always redirect to your local machine :P)

I should also note that you can have multiple projects in the same virtual machine, new projects can be added by adding:

  • A new host/vm folder mapping
  • A new domain/folder mapping
  • A new hosts file entry

Example HomesteadYAML:

ip: "192.168.10.10"
memory: 2048
cpus: 1

authorize: C:/Users/Jeff/.ssh/id_rsa.pub

keys:
   - C:/Users/Jeff/.ssh/id_rsa

folders:
   - map: C:/Users/Jeff/Desktop/Code
     to: /home/vagrant/Code
   - map: C:/Users/Jeff/Dev/NewProject
     to: /home/vagrant/Dev/NewProject

 sites:
   - map: homestead.app
     to: /home/vagrant/Code/laravel-photo-gallery-build3/public
   - map: newproject.dev
     to: /home/vagrant/Dev/NewProject/public


 variables:
  - key: APP_ENV
    value: local 

Example hosts file addition:

...
127.0.0.1 homestead.app
127.0.0.1 newproject.dev