I am running Vagrant on Windows 8.1 using Puphpet. Using following sync settings:
source: ../
target: /var/www/myserver
sync_type: default
As far as I know ../ should sync the parent folder of the vagrant, but its syncing the same folder its in.
EDIT: Let's say I have folder structure like /folder1/folder2 and here I have vagrantfile folder1/folder2/Vagrantfile now I wanted to sync the folder1. It doesn't matter if I have ./ or ../ folder2 will be synced. I want to sync the parent folder (folder1).
How can I sync the parent folder of the vagrant file?
All directories use the location of the Vagrantfile as the base:
https://github.com/puphpet/puphpet/blob/master/src/Puphpet/Extension/VagrantfileLocalBundle/Resources/views/Vagrantfile.rb.twig#L3
dir = File.dirname(File.expand_path(__FILE__))
To share the actual directory containing your Vagrantfile (and everything within), use ./.
Related
I have a Windows 10 guest managed by vagrant, and a python app directory synced:
#Vagrantfile
config.vm.synced_folder "../python_app", "/vagrant_data"
I want to have a venv in both OSX host and Windows guest, but get error when trying to create in the guest:
Error: Unable to create directory 'C:\\vagrant_data'
In the guest box, C:\vagrant_data contains the python_app files.
And it is symlinked to another directory in the guest:
Directory of C:\
11/18/2020 03:34 PM <DIR> Users
etc...
11/18/2020 03:17 PM <SYMLINKD> vagrant [\\vboxsvr\vagrant]
11/18/2020 03:17 PM <SYMLINKD> vagrant_data [\\vboxsvr\vagrant_data]
I am able to create a file:
echo hello world > vagrant_data\hello.txt
Or a directory:
mkdir vagrant_data\removeme
These files appear in the host directory as well.
There isn't already a Scripts or Lib directory.
There is, however a pyvenv.cfg file, which contains details from the host (osx):
home = /usr/local/bin
include-system-site-packages = false
version = 3.8.6
Despite that I have py --version 3.9 in the guest, the home location will obviously be different.
Is a good solution to exclude specified files within the synced directory?
Another option is, of course to not sync at all and use the Git remote to pass files from the devbox to the test environment.
Vagrant's rsync solution
does a one-time one-way sync from the machine running to the machine being started by Vagrant.
What makes much more sense is to simple move the venv into a directory above the synced folder, like this:
config.vm.synced_folder "../my_venv/python_app", "/my_venv/python_app"
(Syncing a folder that's next to, rather than within the one that the Vagrantfile is located in)
In this way, only the second directory is synced, but the first is created. So I vagrant ssh into the guest, cd into the directory above the synced one and create the venv there.
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
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.
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.
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.