Vagrant synced folders disappearing - vagrant

I'm using vagrant and have hashicorp/precise32 box. My projects in /products/ folder on this box. I want to reach this folder from my host computer. So added this configuration to my Vagrantfile
config.vm.synced_folder "/products","/products"
Also created /products folder on host. But after reload when I connect to box over SSH, /products folder's all contents are disappearing. When I comment out the config.vm.synced_folder line and reload, contents appering again.
Can you please tell me what's I missing?
Thank you.

Vagrant sync folder works the other way around
Synced folders enable Vagrant to sync a folder on the host machine to
the guest machine, allowing you to continue working on your project's
files on your host machine, but use the resources in the guest machine
to compile or run your project.
so if you have an existing folder on your guest machine and you ask vagrant to create a sync folder with one of your folder from the host, it will do but replace the content from the content of your host.
There is an old question with some good reference to understand it further

Related

How to switch synced folder without reloading Vagrant?

Environment: Windows Host running Vagrant and VirtualBox with Ubuntu as the guest OS
Background: Doing basic provisioning inside Vagrantfile
When switching between various sites, I have found that I have to first run vagrant halt, cd in the Windows CLI to the base folder of the site I next want to work on (where the Vagrantfile is stored), and then vagrant up again in order for the synced folder in the guest OS to be mapped correctly to the code folder on the Windows host. This shutting down and restarting takes more time than I would like. I tried simply running vagrant provision after cd'ing in the Windows CLI to the folder of the site I want to work on, but this did not re-map the synced folder. I also tried vagrant suspend, cd'ed to another site folder, and then ran vagrant resume --provision, but this did not re-map the synced folder either. Is there any way to re-map the synced folder without going through the vagrant halt, cd another_site, vagrant up sequence?
1 Vagrantfile = 1 VirtualBox VM
so basically you're in folder1/ with its own Vagrantfile, you have started and managed this VM. You now want to "switch" to another VM (not just a folder) so you need to shutdown the current VM, go to the folder2 and start this VM.
What you want is to have a single VM and multiple project folder (site) linked within this VM. some projects like homestead let you easily managed this. Otherwise you can manage yourself: you need a single Vagrantfile (so it will be only 1 VM) and then all your projects within this project structure.

What is the logical/conceptual difference between .vagrant and .vagrant.d directory?

I want to know logical/conceptual difference between .vagrant and .vagrant.d directory
And also, what is the difference between the following keys
(Please observe the path of these two) one of which is placed in .vagrant directory and the other one in .vagrant.d directory in Windows 7?
C:\Users\username**.vagrant**\machines\default\virtualbox\private_key
C:\Users\username**.vagrant.d**\insecure_private_key
Could not find anywhere in the documentation and on the Internet as well. Thanks in advance.
.vagrant.d is usually placed in your home folder and stores system-wide data/settings, i.e. downloaded vagrant boxes.
.vagrant is placed in your environment/project folder and stores project-specific settings, i.e. current VM settings.
So if you work in user/myproject, create Vagrantfile there and exec vagrant up, then user/myproject/.vagrant directory will be created with VM specific data.
.vagrant.d/insecure_private_key is default insecure private key to access your VMs, it's replaced by vagrant on first VM start with private_key from project's .vagrant directory. In your example: private_key for default VM started with virtualbox provider.

Full Duplex Shared Folders in Vagrant

I have a guest box that has data I want to sync to the host so that I am able to edit it using an editor on the host. I want any saved changes made on the host to sync back to the guest. I've tried using normal shared folders config.vm.synced_folder "workspace/", "/my/folder/to/sync/" but this just deletes the contents of the guest folder!
I've looked at using rsync but I'm unsure if this supports editing and syncing both ways
Rsync is type performs one-way synchronization fromm host to guest. When you boot the VM, Vagrant copies the contents of the synchronized folder from host to guest. Vagrant does not monitor the folder on the host for any changes. To change this behavior, use the rsync_auto parameter set to true.

With Vagrant, is it possible to run a single VM (scotchbox) using multiple Vagrantfiles?

I currently have multiple dev sites that each use Vagrant and scotchbox. Each site directory has its own copy of scotchbox, but since they're all the same I'd like to have just one scotchbox VM that I can start with any Vagrantfile, where each Vagrantfile would just change the config.vm.synced_folder.
So, for example, let's say I have:
~/Sites/cheese/
~/Sites/bacon/
~/Sites/eggs/
and then
~/Sites/sctoch-box
I'd like to be able to startup and shutdown Vagrant from ~/Sites/cheese/ or ~/Sites/bacon/ and so on without each also having their own copy of scotch-box.
Is that possible?
Yes you could potentially do that - I've not tested and don't think its official supported
but you can create the first VM from your Vagrantfile within the ~/Sites/cheese/ project, once you have created the VM, copy the Vagrant file and .vagrant directory from ~/Sites/cheese/ into ~/Sites/bacon/ and ~/Sites/egges/ so all will point to the same VM. Edit your Vagrantfile within each of your project to change the Vagrantfile if needed.
You will be able to start the VM from any of this project, but as its single VM, if you try to run vagrant from another project directory, it will not work.

Vagrant doesnt open my fuelphp project

I was using a computer with an already configured Vagrant/VirtualBox ambient. Now, I need to put this box in another computer.
So, I do the vagrant package and added the box in my new computer.
So when I go vagrant up and vagrant ssh everything looks perfect, and all my files are there.
But when I try to access my localhost, vagrant just show me "It Works" page.
I guess I'm missing some reference or link to my project or something like that.
I'm using Ubuntu in both computers and my project use FuelPhp.
You have some options here.
First Option
Use a synced folder in your Vagrantfile
e.g
config.vm.synced_folder ".", "/var/www"
This will change your share folder mount in /vagrant/educarebr to /var/www and Apache will see the folder.
Second Option
Create a symbolic link in vagrant using a provisioner, as Shell Script.
Third Option
Create a new virtual host in your Apache with DocumentRoot /vagrant/educarebr.
However, check your old Vagrantfile and compare with your new Vagrantfile that you are using with box created with vagrant package.

Resources