Search code examples
phpsymfonytwigvagranttwig-extension

Symfony 2 through Vagrant on Windows has errors, because Symfony tries to look for twig files using a mish-mash of Windows and Linux paths


Whenever I try to access (almost) any page/route, I get errors like:

ContextErrorException in Filesystem.php line 130: Warning: file_get_contents(C:_CODE\symfony2\vendor\sensio\distribution-bundle\Sensio\Bundle\DistributionBundle/Resources/views/Configurator/Step/doctrine.html.twig): failed to open stream: No such file or directory

Basically, Symfony seems to be piecing together URLs from both the Vagrant/Linux and Windows environments, and thus is unable to find a bunch of twig files.

A little about my setup:

I have my Symfony files on the Windows machine, and they are mapped onto the Vagrant box. I'm just taking advantage of the default "." -> "/vagrant" mapping, and then have the puppet config create a symlink from "/vagrant/web" -> "/var/www" ("." is where both Symfony and the vagrantfile are located). The setup is basically copied from https://github.com/nater1067/Vagrant-Symfony-2. Just to make sure it wasn't me, I used the "stock" git pull from that repo, and went to http://localhost/config (after commenting out the restriction that only allows connections from localhost), and that error above showed up on step 2.

What I've tried:

As you can see from the repo's puppet file, it seems to already properly set the owner of the web files (/var/www/*) to vagrant:vagrant. I've also tried mapping the entire C drive to /vagrant/c. and then using a symlink to get the correct ../%Symfony%/web files into /var/www, but that didn't work either. I've also tried setting the permissions to 777 for all directories and files under /var/www.

The question:

Is there something else I need to do with a Windows/Vagrant/Symfony setup to make sure Symfony doesn't try to piece together Linux and Windows paths? My next step is to just give up, and sftp the files from Windows to the vagrant box.


Solution

  • Are you executing any symfony commands on your local machine? Basically you should just edit files through your IDE and everything else should be on vagrant machine. Symfony by itself will never be aware of the fact that there is another OS involved. As long as you run everything from the virtual machine this should never happen.