Search code examples
symfonyvagrant

Vagrant 2 way folder sync


I've setup a Vagrant box that runs my webserver to host my Symfony2 application. Everything works fine except the folder synchronization.

I tried 2 things:

  1. config.vm.synced_folder LOCALFOLDER, HOSTFOLDER
  2. config.vm.synced_folder LOCALFOLDER, HOSTFOLDER, type="rsync"

Option 1: First option works, I actually don't know how file is shared but it works. Files are copied in both way, but the application is SUPER slow. Symfony is generating cache files which might be the issue, but I don't really know how to troubleshoot this and see what is happening.

Option 2: Sync is only done in one way (from my local machine to the vagrant box), which covers most of the case and is fast. Issue is that when I use symfony command line on the vagrant box to generate some files they are not copied over to my local machine.

My question is: What is the best way to proceed with 2 ways syncing? With option 1 how can I (as it might be the issue) exclude some files from syncing. With Option 2 how can I make sure changes on remote are copied to my local machine?


Solution

  • As it doesn't seem Vagrant offers a "built-in" way to do this here is what I did:

    • Configure Vagrant RSYNC folder on the folders that will contains application generated files (in Symfony2 it is your Bundle/Entity folder). Note that I didn't sync the root folder because some folders doesn't have to be rsynced (cache/logs...) and also because it was taking way too much time for the rsync process to parse all the folders/subfolders when I know that only the Entity folder will be generated. As the Rsync has to be done from the Vagrant box to the host, I use vagrant-rsync-back plugin and thus run this manually everytime I use a command that generates code. https://github.com/smerrill/vagrant-rsync-back#getting-started

    • Create an watcher on my local machine that will track any change in code and rsync it to the vagrant box. https://gist.github.com/laurentlemaire/e423b4994c7452cddbd2