Vagrant and symfony2

apache, macos, php, symfony, vagrant

Solution

Update as of 15th Jan 2016. Instructions for Vagrant 1.7.4+ and Symfony 3. This works.

On a fresh Ubuntu 14.04 install, ACL was installed but I couldn't use +a or setfacl to fix the permissions issues, and of course, as soon as you change any permissions in terminal in vagrant, they're reset to vagrant:vagrant again.

I added the following to my vagrant file:

# Symfony needs to be able to write to it's cache, logs and sessions directory in var/
config.vm.synced_folder "./var", "/vagrant/var",
 :owner => 'vagrant',
 :group => 'www-data',
 :mount_options => ["dmode=775","fmode=666"]

This tells Vagrant to sync var/logs and var/cache (not to be confused with /var/, these are in the root Symfony directory) and have them owned by vagrant:www-data. This is the same as doing a `sudo chown vagrant:www-data var/`, except Vagrant now does it for you and enforces that instead of enforcing vagrant:vagrant.

Note there are no 777 'hacks' here.

As soon as I added that, I didn't get any more permissions errors in the apache log and I got a nice Symfony welcome screen. I hope that helps someone!

Problem

I'm having kind of a bizzare issue related to installing Symfony2 from within a vagrant environment. The environment is set up correctly and is running a web server that is serving files from a folder that is shared with the vagrant environment that is located in the base directory of vagrant. Basically, vagrant is initiated in directory foo and then within foo, there is a directory called webroot. Vagrant automagically shares the foo directory. An apache server is set up to run so that webroot is the base http directory. This all works fine and I am able to serve basic HTML, PHP and the MySQL connection is tested to be fine. I used composer to install vagrant the recommended way, into directory inside /webroot/ called Symfony. All of the files now exist within the correct directory. The configuration is correct and there are no items that Symfony claims need to be changed in /config.php. The issue comes when I attempt to load /app_dev.php. It throws an exception claiming that it cannot create a file named cache in the /app directory. As chmod +a is not supported within the vagrant box I am using, I elected to set permissions by uncommenting umask(0000) in app_dev. Assuming it was a permission problem, I tried using chmod to adjust the permissions both within the vagrant environment and within osx to 777 for everything. What's strange is that when I chmod a file or directory inside the vagrant environment, it claims to set 777 correctly but then when I ls -l, the permissions have not changed. However, when I chmod a file or directory from OUTSIDE The vagrant environment within the webroot folder, the permissions persist. As symfony does not have r/w permissions within the environment, it cannot create the necessary cache and log files. When i run symfony from the command from osx, everything works fine. Does anyone have any insight as to how to change the permissions for the /webroot directory so things within the vagrant environment can actually read and write to it as chmod doesn't appear to work?

Original source