Cannot access Vagrant shared folders - vagrant

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.

Related

Vagrant permission with drupal using nfs

I use vagrant as environment on OSX (made with PUPHPET), and i use NFS for synced folder.
But i tried to install drupal on it, and the installation failed because of non writable file.
Do you have any solution to change permission on NFS synced folder ? or should i use something different synced folder ?
Error
The website encountered an unexpected error. Please try again later.
Exception: The directory <em class="placeholder">sites/default/files/config_UoG7KuH42rAreqqHW3qJvJP1SKbBL5Bsoln_xR2lZ4cXUkSW7M3ZCb-QyQi3vFJ8zr5pdnWuPQ/sync</em> could not be created or could not be made writable. To proceed with the installation, either create the directory and modify its permissions manually or ensure that the installer has the permissions to create it automatically. For more information, see the online handbook. in drupal_install_config_directories() (line 508 of core/includes/install.inc).
You can modify the owner, group, and permissions of a synced folder using Vagrant...
config.vm.synced_folder "foo/", "/opt/foo",
owner: "www-data",
group: "www-data",
mount_options: ["dmode=775", "fmode=664"]
The www-data user is the default user for both Apache and Nginx, so that's probably what you'll want to use. In the mount options, dmode sets permissions on directories while fmode sets permissions on files. Details for synced folders are in the Vagrant docs.
If you don't want to edit the Vagrantfile directly, then I'm not sure if there's a relevant configuration option within PuPHPet that you can change.

Vagrant and synced folders: How to set the owner to a user other than the default vagrant user?

I am trying to set up a development environment for a Rails 2 project within a CoreOS Vagrant VM that has a number of moving parts.
Once the VM is provisioned there is a Puppet script that installs all the bits and pieces and starts them up.
The bit that I am working on, which is on my local machine (OS X 10.10.5), is exposed in to the VM via a synced folder and appears in the right place in the VM with owner vagrant and group vagrant.
In order for it to work with the rest of the system the owership of that folder needs to be set to projectx instead.
Simply telling Puppet to set the permissions doesn't work. They don't change. I've confirmed this by manually chowning the files and they don't change.
I can't just set the user in the Vagrantfile though as, until Puppet has done its stuff there is no projectx user.
It's looking like my only solution is to hack the Puppet files and eliminate the use of the projectx user but I'd rather find a way to set the owner of the synced folder instead as that would be much cleaner.
How do I set the ownership of a synced folder to a user that is not created until after the VM has been provisioned?
Unfortunately there are no easy ways to do that.
Common workaround is to use uid and gid in sync folder configuration. This way you can create a synced folder as a user who will be added to the system later.
projectx_uid = 1001
projectx_gid = 1001
config.vm.synced_folder "src/", "/srv/website",
owner: projectx_uid, group: projectx_guid0
This means projectx should be created at the very beginning of the provisioning process so it will have predictable uid/gid
Related issue in Vagrant's tracker: https://github.com/mitchellh/vagrant/issues/936

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.

Understanding Vagrant Synced folder setup with the default & html folder

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.

How can I set permissions for Magento using a Vagrant shared folder?

I am trying to install a Magento instance using vagrant. I used the MageVagrant repository found here, then modified it so that the default installtion directory on the vagrant machine points to a folder in the /vagrant folder, which is the shared folder (I did this so that I could edit the Magento files on my local machine and store them in version control), so that on my vagrant machine I have a symlink that looks like the following:
/srv/www/magento.localhost.com -> /vagrant/magento.localhost.com
When I try to run the Magento installer, it is fine until I get to the Configuration step of installation, and then I get the following error message:
Path "/srv/www/magento.localhost.com/public_html/app/etc" must be writable.
Path "/srv/www/magento.localhost.com/public_html/var" must be writable.
Path "/srv/www/magento.localhost.com/public_html/media" must be writable.
even though I have run chmod 777 -R on the directories both on my local machine and on the vagrant box. However, it still thinks it is not writable. How can I make these directories writable for the vagrant server?
By default it makes the mounted folder owned by the vagrant user and group, so you could make the web server you are using have permissions for that, or the way I do it is to add another shared folder and explicitly set the permissions on that share to how I want.
Line in my VagrantFile:
config.vm.synced_folder "../project_folder", "/var/www/", owner: "apache", group: "apache"
this will mount the folder "project_folder" which is one level above my vagrant directory to the location "/var/www" inside the virtual machine with the ownership of apache:apache.
This should work.
If you are hosting multiple sites inside the vm I suggest setting this shared folder as the parent of all the sites.

Resources