Search code examples
linuxvagrantvirtual-machine

Accessing a file from the browser from a vagrant box


I'm very new to Vagrant/ using vm boxes on a daily basis and cant seem to figure out how to access a file that I've shared from my local machine, to the vm, through the browser. I've got a shared folder going to the root home/vagrant which is the directory I'm navigated to when logging in using vagrant ssh. Then opening up a browser and typing in localhost:8000/index.html i get a 404 not found.

I know i'm doing something very wrong and probably using Vagrant incorrectly but at the same time feel like I'm just not pointing my shared folder to the right place.

-- Edit --

So far my vagrantfile a provisioning looks like

Vagrant.configure("2") do |config|
    config.vm.box = "scotch/box"
    config.vm.network "forwarded_port", guest: 80, host: 9001
    config.vm.provision :shell, path: "bootstrap.sh"
    config.vm.synced_folder ".", "/var/www"
end
apt-get update
apt-get install -y apache2
if ! [ -L /var/www ]; then
  ln -fs /vagrant /var/www
fi

Solution

  • Figured it out, it was a combination of pointing my shared folder to the correct place in the vm using

    config.vm.synced_folder "./dist/src", "/var/www"

    cding into that directory and then using

    php -S <-IP->:8000