Vagrant and symfony2 Vagrant and symfony2 php php

Vagrant and symfony2


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!


I think it's a question of user rights. Your apache + php is probably launched by root. You have to set rights with root.

Two possibilities :

sudo suchmod -R 777 app/cache

or

sudo chown -v app/cachesudo chmod -R 777 app/cache

You will probably have to do the same thing with the log file.

My vagrant file if you need it :

# -*- mode: ruby -*-# vi: set ft=ruby :Vagrant.configure("2") do |config|  config.vm.box = "precise64"  #Box Name  config.vm.box_url = "http://files.vagrantup.com/precise64.box" #Box Location  config.vm.provider :virtualbox do |virtualbox|      virtualbox.customize ["modifyvm", :id, "--memory", "2048"]  end  config.vm.synced_folder ".", "/home/vagrant/synced/", :nfs => true  #config.vm.network :forwarded_port, guest: 80, host: 8080 # Forward 8080 rquest to vagrant 80 port  config.vm.network :private_network, ip: "1.2.3.4"  config.vm.network :public_network  config.vm.provision :shell, :path => "vagrant.sh"end

vagrant.sh

#!/usr/bin/env bash#VM Global Configapt-get update#Linux requirementapt-get install -y vim git#Apache Installapt-get install -y apache2#Apache Configurationrm -rf /var/wwwln -fs /home/vagrant/synced/web /var/wwwchmod -R 755 /home/vagrant/synced#Php Installapt-get install -y python-software-propertiesadd-apt-repository -y ppa:ondrej/php5apt-get updateapt-get install -y php5 libapache2-mod-php5#Php Diversapt-get install -y php5-intl php-apc php5-gd php5-curl#PhpUnitapt-get install -y phpunitpear upgrade pearpear channel-discover pear.phpunit.depear channel-discover components.ez.nopear channel-discover pear.symfony.compear install --alldeps phpunit/PHPUnit#Php Configurationsed -i "s/upload_max_filesize = 2M/upload_max_filesize = 10M/" /etc/php5/apache2/php.inised -i "s/short_open_tag = On/short_open_tag = Off/" /etc/php5/apache2/php.inised -i "s/;date.timezone =/date.timezone = Europe\/London/" /etc/php5/apache2/php.inised -i "s/memory_limit = 128M/memory_limit = 1024M/" /etc/php5/apache2/php.inised -i "s/_errors = Off/_errors = On/" /etc/php5/apache2/php.ini#Reload apache configuration/etc/init.d/apache2 reload#Composerphp -r "eval('?>'.file_get_contents('https://getcomposer.org/installer'));"mv -f composer.phar /usr/local/bin/composer.pharalias composer='/usr/local/bin/composer.phar'#Postgresapt-get install -y postgresql postgresql-client postgresql-client php5-pgsqlsu - postgres -c "psql -U postgres -d postgres -c \"alter user postgres with password 'vagrant';\""


An updated answer for nfs:

config.vm.synced_folder "www", "/var/www", type:nfs, :nfs => { :mount_options => ["dmode=777","fmode=777"] }