Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

aconder1126's avatar

I want to access server running in Homstead VM on my main machine.

In the VM I began a new Laravel project using command:

laravel new blog

The when I run the local server for the project:

php artisan serve

On my VM this server starts:

127.0.0.1:8000

How do I access content on this server on my main computer in the browser?

0 likes
6 replies
Cronix's avatar

You don't run artisan serve on the homestead vm. It's running NginX. If you followed the instructions on installing homestead and didn't change the host name in the sites section of homestead.yaml, you'd access it with http://homestead.app ` Stock homestead.yaml file contains:

sites:
    - map: homestead.app
      to: /home/vagrant/Code/Laravel/public

You'd also need to add an entry in your hosts file on your host computer (not homestead vm) as the instructions say.

1 like
aconder1126's avatar

Thanks, maybe the problem was that I ran bash init.sh in the master branch and vagrant up in another. I read the docs and even went through a tutorial in a book I purchased on Laravel, and I have a few clarifying questions if you could please help explain.

I have done a reinstall of the box and am going to try again. Please help me so I feel comfortable I understand what's going to happen when I press vagrant up, lol.

Here is hosts file on my computer.

127.0.0.1 localhost

192.168.10.10 homestead.app

192.168.10.10  homestead  # VAGRANT: 45876ff9f3e619fedd39096e8430fecb (homestead-7) / 0dd1e4f6-ef05-48fc-a6c0-2776c9fa3bdc
192.168.33.34  apache  # VAGRANT: 4a27dff1fcda124efc218bd897ff784c (apache) / b30b37f4-0e90-4294-a624-13e5ce1d316b

homestead dir. on my local machine is at

me@mycomputer-MINGW64 $ ~/Homestead/homestead ((v5.2.4))

My homestead.yaml

folders:
    - map: ~/Code
      to: /home/vagrant/Code

sites:
    - map: homestead.app
      to: /home/vagrant/Code/Laravel/public

databases:
    - homestead

The docs said once vagrant up is run, the .yaml file will automatically configure the nginx server and shared folders. It specified that this folder trees such as /home/vagrant/Code would be created then. However when ssh'd into the macine I could not find these file trees.

A few questions:

  1. Should I mkdir ~/Code or assume it will be created on my host machine?

  2. I know the name is arbitrary but is ~/Code just a stand in for wherever the homestead file from git is located? If so should I change it to

folders:
    - map: ~/Homestead/homstead
      to: /home/vagrant/Code
  1. When I see /home/vagrant/Code I see a file tree starting from the root directory of the vagrant machine. Is it more accurate to view this as ~/home/vagrant/Code?

  2. I want to work on a new laravel project using this virtual box, am I to assume that it will be located in the /home/vagrant/code/Laravel/public directory tree or do I need to laravel new project in one of my shared folders?

Cronix's avatar

It doesn't have to be ~/Code. It's just wherever on your host machine you have the "code" that you want to be linked to on the vm. It can be a single laravel install, or a directory with many project dirs and each one can be "mapped" to a url. Note that ~/Code is your code directory, not the dir where homestead is installed.

Then in the Sites section, you just define which directories map to which domains (the document_root).

When I see /home/vagrant/Code I see a file tree starting from the root directory of the vagrant machine. Is it more accurate to view this as ~/home/vagrant/Code?

Almost, when ssh'd into the vm, it would represent the home dir for the vagrant user, so it would be accurate to view it as ~/Code

I want to work on a new laravel project using this virtual box, am I to assume that it will be located in the /home/vagrant/code/Laravel/public directory tree or do I need to laravel new project in one of my shared folders?

If you want to keep the structure as is in your homestead.yaml file you would:

  1. Create a ~/Code dir on your host computer

  2. Install laravel into ~/Code/Laravel

  3. cd into ~/Homestead/homestead

  4. run 'vagrant up'

  5. visit homestead.app in your browser. You should see the laravel page.

1 like
aconder1126's avatar

Thanks a ton. I am a little worried now that the info I posted in my hosts file could open me up to security vulnerabilities, any idea about that, because vagrant is acting like my hosts file doesn't exist now and spitting a weird error.

Cronix's avatar

I'm not sure what these 2 lines are in your hosts file:

192.168.10.10  homestead  # VAGRANT: 45876ff9f3e619fedd39096e8430fecb (homestead-7) / 0dd1e4f6-ef05-48fc-a6c0-2776c9fa3bdc
192.168.33.34  apache  # VAGRANT: 4a27dff1fcda124efc218bd897ff784c (apache) / b30b37f4-0e90-4294-a624-13e5ce1d316b

Did you add those in? I'd get rid of them (or comment them out) and just keep

127.0.0.1 localhost
192.168.10.10 homestead.app
lupinitylabs's avatar

Even though this question is pretty old: artisan serve does indeed work on Homestead. By default, it serves to localhost only, however, so to make it accessible from the host system, you need to

artisan serve --host 0.0.0.0

You can then access the site from the hostsystem at the configured address (192.168.10.10 by default):

http://192.168.10.10:8000

Hope that helps :-)

Please or to participate in this conversation.