Vagrant permission with drupal using nfs - macos

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.

Related

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

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.

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.

Is there a way to unsync a subfolder in Vagrant?

There are few subfolders in my project folder that wouldn't need to be synced to the guest machine. (In particular the .git folder, which contains >800 files.) Is there a way to unsync subfolders of a synced folder in Vagrant? Or how should I prevent unneeded folders from being synced?
Disabling sync this way doesn't seem to work, when /vagrant/ is synced by default:
config.vm.synced_folder "www/kisa/.git/", "/vagrant/www/kisa/.git/", disabled: true
Normally (with vboxsf, vmhgfs, NFS, ...) the syncing is done by mounting the specified directory from the host to the guest. For performance reasons there should be no need to prevent some content from "syncing", as the data is not transferred unless you access it from the guest. If you write the data on the guest but don't want to sync it back to the host, easiest is to write it somewhere else. =)
The upcoming Vagrant 1.5 will include rsync synced folders which will support rsync__exclude option. Some cloud provider plugins (aws, digital_ocean, ..) already use rsync, but support for excluding depends on the provider. In some cases you just have to sync only the wanted folders separately. You can disable the default sync with
config.vm.synced_folder ".", "/vagrant", disabled: true
I can't pretend to understand this, but the method shown at this. seems to work for me for a Linux (Ubuntu) guest on a windows 7 host.
I wanted to use it for exactly what he describes - to exclude a node_modules directory from being shared.
In case the link disappears the gist is:
$ mkdir ~/vagrant_node_modules
$ sudo mount --bind ~/vagrant_node_modules /vagrant/node_modules
so that /vagrant is shared but /vagrant/node_modules is not.
Someone more knowledgeable than me might know if there are problems with this.

Resources