Understanding Vagrant Synced folder setup with the default & html folder - vagrant

I'm working on getting a Vagrant setup running for the first time on a Windows 8.1 machine. I've been pouring over all the documentation to understand how it all works. I used puphpet to help me configure a Ubuntu 14 LAMP development box to use.
My confusion is around how the synced folders are setup. It seems that the synced folders on install, always create a new 'default' and 'html' folder in whatever local directory I specify in my puphpet setup. I then have to put any code files I want to run in the default folder.
For example: host folder: ./www ends up having /www/default and www//html in it after Vagrant up. Why is this occurring? I left the remote folder to the default /var/www.
My ideal setup was to have a Vagrant box folder setup on my machine, and then have my code project reside in the same directory as the Vagrant box files. However, it seems that I can only put the code project in the 'default' directory that Vagrant creates.
I can't find any mention of this in the documentation. Is this normal behaviour for this to be happening? If not, how can I get around this so that I can keep the code in whatever directory that I want?
Here's the relevant code from the puphpet config file:
synced_folder:
Rh7fCuil7xE4:
source: ./www
target: /var/www
sync_type: default
rsync:
args: '-z'
exclude: .vagrant/
auto: 'false'

Author of puphpet here.
Nginx creates a folder for its default vhost (same with Apache). That's what those two folders are. It also appears there's a small bug in puphpet that will create both folders, even though one is the right one. I'll see about fixing it, but it shouldn't affect your VM in the slightest.
/var/www is what you've defined as your target, so anything that appears in your master's ./www will also appear in your VM's /var/www and vice-versa.

Related

Multiple Homestead Boxes

I'm trying to install multiple of the same homestead box. Each one for a different project, totally isolated from each other. None of them will be run concurrently, only one at a time.
But when I try to run vagrant up, it tells me that a box with the name 'homestead-7' already exists. How can I rename it?
I don't see the name anywhere in the vagrantfile in the project directory, nor any 'boxes' folder in either the project .vagrant directory or my home .vagrant directory. vagrant global-status tells me that there is 1 homestead-7 box already for the project that is already in progress.
You need to add "name" property under your "Homestead.yaml" file, for example:
name: my-new-homestead
and make sure that your authorize, keys and folders are pointing to the correct path.
To use Homestead in a per project basis, you need to add it as a dependency in each one of your projects:
composer require laravel/homestead --dev
Use php vendor/bin/homestead make to generate the Vagrantfile and Homestead.yaml files. Then you can simply run vagrant up from your project.
See more on the Laravel documentation.

Vagrant synced folder link to Apache /var/www/ in Ubuntu VM

I'm not sure how to phrase the title; hopefully, it made sense. I am learning about Vagrant and just found out about synced folders. I am doing web development and want to edit/create my files and folders on my local machine instead of Ubuntu 14.04 (on Vagrant).
I store my files in my /vagrant/ folder, which end up appearing on both machines. This is perfect. I want these folders/files to be automatically moved to /var/www/ as soon as a file or folder is changed in the synced folder.
For example:
Make folder on Windows 10 called test inside the synced folder. Put index.html inside test.
The folder and file are uploaded to the Ubuntu machine.
Inside of /var/www/ in the Ubuntu machine, there should be a copy of the test folder along with all the files inside of it.
The test folder inside /var/www/ updates if any changes are made in the synced folder /vagrant/.
I was looking into the ln command but I keep getting an error saying "hard links not allowed". I was trying like this on Ubuntu:
cd /vagrant
ln test /var/www/
Should I approach this differently? How can I accomplish what I want to do? Thanks in advance!
You can do sharing folder using vagrant, it is called synced folder in Vagrant terminology
If you want to sync the guest /var/www you can add the following in your Vagrantfile
config.vm.synced_folder "www/", "/var/www"
so if you create the www/ folder within your local/host project folder, any files that you will save under this www folder will automatically be synchronized with the /var/www folder of your ubuntu machine
vagrant/virtualbox do not really limit you in the number of sync folder so you should adopt that rather than using one and work with symlink.
Another way of syncing your folder is to create a soft link in linux. Just type this into your command line:
rm -rf /var/www
ln -fs /vagrant /var/www
This will remove the /var/www folder and create a soft link so that whoever tries to go to /var/www will be automatically be redirected to your synced folder which in this case is /vagrant but you can change that to something different.
you can also create a shell script for this so that every time you create a virtual instance, it can automatically do this for you instead of you having to manually do it every time.
Here is a link to how to make the vagrant file run a shell script when you vagrant up:
https://www.vagrantup.com/docs/getting-started/provisioning.html

Vagrant synced folders disappearing

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

Cannot access Vagrant shared folders

I just trying to add Vagrant to my workflow and I have following probably noob problem. I pull standard hashicorp standard 14.04 image, vagrant up it, SSH to it install my python requirements on it and then then try to execute build commands against code in Vagrant shared folder and run in to problems. Basic errors I get say those locations don't exist or cannot be found.
First action I, go ls /vagrant and can see my shared folders. I cannot cd to them from Vagrant machine I have tried to halt the machine.
Vagrantfile shared folder code.
{"virtualbox":{"/vagrant":{"guestpath":"/vagrant","hostpath":"/Users/Kimmo/Documents/Mist.io","disabled":false}}}
I am using Virtualbox as provider newest version.
My dev machine is OSX 10.9.5
There are not access limitations on the folder itself.
Thanks for you help in advance :)
Does /vagrant exists inside the VM just after you start it ?
If no you can add this parameter : "create":true. According to the doc, for the create: true paramater : If true, the host path will be created if it does not exist. Defaults to false.
If the folder /vagrant exists but you can cd or ls it, you can add parameters wich will define the right/owner of this folder:
owner: (string) the user who should be the owner of this synced folder. By default this will be the SSH user. Some synced folder types don't support modifying the owner.
group: (string) the group that will own the synced folder. By default this will be the SSH user. Some synced folder types don't support modifying the group.
Also for the hostpath parameter you have to give him a folder path, not a file path. In your conf I can see: "hostpath":"/Users/Kimmo/Documents/Mist.io". If Mist.io is a file and you want to access this file inside your VM, just give the path to the folder containing this file, /Users/Kimmo/Documents in your case.

Vagrant syncing process

I've just started using Vagrant and I've managed to set up a box ok it seems. I have been a little confused about syncing folders work though. I took from Vagrant that syncing allowed you to use the file system on your Mac and then sync those changes into your virtual machine, is that right?
I have these settings currently
config.vm.synced_folder "../../../Library/WebServer/Documents/", "/Users/jonnny/ubuntu-vagrant/www"
I would expect that now that when I look in chrome that inside my 127.0.0.1:1234/www/
That the files within my Library/WebServer/Documents/ would be there. But they're not, have I done it wrong or misunderstood what's going on here?
Update
I wasn't sure what you meant with my file/folder structure, so probably best I just show them.
Users
Jonnny
ubuntu-vagrant
- Vagrantfile
- /www (dir)
- bootstrap.sh
VagrantFile
VirtualBox VMs
- ubuntu-vagrant_342374982374923
- box-disk1.vmdk
- logs (dir)
- ubuntu-vagrant_342374982374923.vbox
I did try your suggestion and reload the box, but the folder still didn't seem synced.
The syntax seems to be correct. But for the second argument, /Users/jonnny/ubuntu-vagrant/www, it should be the targeted location inside the ubuntu filesystem, not the one which will be created on your Mac OS filesystem.
Try something like /www/ or /usr/johnny/www, according to the location you want.
Update
For the vagrant arguments:
the first should be the location of the folder you want to share inside your Mac Os filesystem relatively from where the Vagrantfile is in your Mac Os filesystem.
the second is where inside the ubuntu-vagrant filesystem you want to access these files.
I think your folder structure is not good: you dont need a Vagrantfile folder or a www folder in your Mac OS filesystem. Just consider one folder: the one where the Vagrantfile is, Users/Johhny/ubuntu-vagrant. The www folder will just exists inside the VM. Then if the Library folder is at the same level than the Users folder in your Mac OS filesystem, you should have :
Library
...
Users
Johhny
ubuntu-vagrant
Vagrantfile
bootstrap.sh
And inside the Vagrantfile you should have this line :
config.vm.synced_folder "../../../Library/WebServer/Documents/", "/www", create: true
According to the doc, for the create: true paramater : If true, the host path will be created if it does not exist. Defaults to false.

Resources