This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use Stack Overflow.

Running Symfony 2 on vagrant

Discuss installing Symfony 2 here

Running Symfony 2 on vagrant

by netmikey » Tue Oct 30, 2012 3:57 pm

Hi everyone,

I'm new to Symfony. I'm trying to set up the standard edition on a vagrant box, but it looks like I have some issues with write permissions on the mounted file system. Here's my Vagrantfile:
Code: Select all
Vagrant::Config.run do |config|
  config.vm.box = "squeeze64" # just a basic debian squeeze box
  config.vm.forward_port 80, 8080
  config.vm.share_folder("v-root", "/vagrant", ".", :extra => 'dmode=777,fmode=777')
end

As you can see, I already modified the default config so that files and directories get mounted world-writable (I tried group-writable before and added the www-data user to the vagrant group without success).
In dev mode, the webserver user builds the caches on first access just fine. But when I run
Code: Select all
php app/console cache:clear
, even as root(!), I get:
Code: Select all
Clearing the cache for the dev environment with debug true

[Symfony\Component\Filesystem\Exception\IOException]               
  Failed to remove directory /vagrant/app/cache/dev_old/jms_security


Can anyone reproduce / solve this problem? Or has anyone successfully used Symfony 2 on vagrant before?
I don't want to use vagrant nfs mounts because we have windows devs which wouldn't be able to do that...

Best regards,
Mike
netmikey
Junior Member
 
Posts: 3
Joined: Tue Oct 30, 2012 3:43 pm

Re: Running Symfony 2 on vagrant

by netmikey » Wed Oct 31, 2012 10:30 am

After a whole day of fiddling around, I think I can answer my own question now:

It looks like the issue is caused by VirtualBox's shared folders not working properly for my host/guest combination. It appears that, if you use a MacOS host (in fact, any *nix type host I think), with a linux vm, the performance of VirtualBox's shared folders gets worse the more files are in your shared folder (See [1]). Symfony was, in fact, performing _very_ poorly on my vm (with requests to the demo app taking 5-10 Seconds(!)). It turned out that this was caused by poor VirtualBox disk IO to the shared folder.

Moreover, it turned out that the error I described in my initial post was also caused by VB's shared folder IO. I switched to nfs shares and everything is working, plus it's really fast now. So for fellow googlers, here's my Vagrantfile:

Code: Select all
Vagrant::Config.run do |config|
  config.vm.box = "squeeze64"
  config.vm.network :hostonly, "192.168.33.10" # Host-Only networking required for nfs shares
  config.vm.forward_port 80, 8080
  config.vm.share_folder("webdev","/var/www/",".", :nfs => (RUBY_PLATFORM =~ /linux/ or RUBY_PLATFORM =~ /darwin/))
end


A couple of gotchas about nfs shared folders:
  • Since vagrant will need to configure `nfsd` on the host (for the vm to connect to), it will ask for the user's password on each `vagrant up` so it can access `/etc/exports` and (re)stard `nfsd`.
  • The owner and group of the shared files on the vm will look wrong (will be those of the host, which probably don't match these of the vm). It took me a while to figure out that the files/folders are writable for all vm users anyway. Seems magical, but at least, it works ;)

Note: The info in this post might only apply for *nix type hosts. I have not tested this on a Windows host yet, but shared folders might work well there (and since Windows users don't have the nfs option, It better does ;)). This is why my Vagrantfile decides whether nfs should be used or not by evaluating the host os (credits to [2]).

[1]: http://vagrantup.com/v1/docs/nfs.html
[2]: http://treehouseagency.com/blog/steven- ... nt-and-nfs
netmikey
Junior Member
 
Posts: 3
Joined: Tue Oct 30, 2012 3:43 pm

Re: Running Symfony 2 on vagrant

by kiwiguy2013 » Thu Jan 24, 2013 12:00 am

Thanks so much for posting this information, this totally saved me hours of frustration, worked like a charm! This information should be included in formal Symfony installation guides for those wanting to install Symfony on a Virtual machine.

Thanks again!
kiwiguy2013
Junior Member
 
Posts: 1
Joined: Wed Jan 23, 2013 11:55 pm

Re: Running Symfony 2 on vagrant

by smartius » Fri Feb 01, 2013 1:26 pm

i ve recently created a vagrant box for sf2 development which includes most necessary stuff:

┬┤https://github.com/caramba1337/vagrant-symfony2-nginx-php54fpm-dev-box
smartius
Junior Member
 
Posts: 1
Joined: Fri Feb 01, 2013 1:25 pm

Re: Running Symfony 2 on vagrant

by niaxilin » Tue Feb 12, 2013 4:54 pm

netmikey wrote:After a whole day of fiddling around, I think I can answer my own question now...

Thank you! I have the same setup with the same problem and was about to inappropriately curse the Creators [of Symfony]. Forgive me. :D
niaxilin
Junior Member
 
Posts: 1
Joined: Tue Feb 12, 2013 4:51 pm

Re: Running Symfony 2 on vagrant

by snance » Mon Mar 04, 2013 10:36 am

I'm getting the exact same issue, however I'm running on a Windows base with Ubuntu 12.04.1 LTS. It's my understanding that you cannot enable nfs with vagrant on windows.

Any idea on how to fix this?

Edit: It's an issue with Virtualbox. See bug report #8761
snance
Junior Member
 
Posts: 5
Joined: Fri Jan 28, 2011 4:46 pm

Re: Running Symfony 2 on vagrant

by seiffert » Tue Mar 19, 2013 10:32 pm

For new projects, you might also have a look at https://github.com/seiffert/symfony-vagrant.
seiffert
Junior Member
 
Posts: 7
Joined: Wed Nov 28, 2012 6:19 pm