0

I am trying to share a folder betwing my vagrant box and my host using this directive in Vagrantfile :

  config.vm.synced_folder "./syncWithBox", "/var/www/html/"

The issue is that the /var/www/html/ folder is created during provisionning (installing apache2 server). So when I vagrant up, there is an error because the /var/www folder does not exist before provisionning ! Is there a way to solve that ? How can I tell vagrant to perform folder sync after provionning ?

I saw a similar question here, but the answer is not exactly what I am looking for

Community
  • 1
  • 1
ben.IT
  • 1,490
  • 2
  • 18
  • 37
  • Are you looking to share the guest's /var/www/html with its contents with the host or vice versa? – nir0s Mar 09 '17 at 18:20
  • I want to share the guest folder /var/www/html/ with the host folder ~/vagrant-box/syncWithBox/ – ben.IT Mar 10 '17 at 09:53
  • That's not how shared directories work using the virtualbox provider. It is a two way sync based on the host's contents. You can always either setup a flie server or use e.g. rsync to do that though. Btw, when you do what you did above, it will create /var/www/html on the guest. – nir0s Mar 10 '17 at 10:34

1 Answers1

0

This workaround works for me. I put the following command in an install.sh script and run it:

    #!/bin/bash
    vagrant plugin install vagrant-vbguest && vagrant up --no-provision 
    sed -i 's/#config.vm.synced_folder/config.vm.synced_folder/' Vagrantfile
    vagrant halt && vagrant up --no-provision 
    vagrant provision
  1. Install vbox addition with vagrant-vbguest plugin and Vagrant up the box without provisioning it
  2. uncomment the synchronized folder directive using sed for example
  3. stop the box and Vagrant it up without provisioning it : so the folders between host and guest are empty but synchronized
  4. finally, provision the box
ben.IT
  • 1,490
  • 2
  • 18
  • 37