title: Laravel 4 Permissions on a Vagrant box with Puppet
body: <p>I have been using <a href="http://www.puphpet.com">http://www.puphpet.com</a> successfully to generate vagrant+puppet environments for a number of projects. Then this week I got tasked with writing a prototype for a project using Laravel 4. Since I'm not going to be the one working on the project full time, I figured it would be best to make a VM environment for it that the next person can just clone for the repo. Not having much experience with Laravel 4 I got everything to run in the dev environment just fine. Then I tried to run the first migration and here the problems start with the <code>app/storage</code> file permissions.</p>
  
  <p><strong>1. app/storage must be writable by the web user</strong></p>
  
  <p>Fine, took out id: vagrant from the synced folder provisioning and set the owner &amp; group to www-data like so:</p>
  
  <pre><code> config.vm.synced_folder "./www", "/var/www", owner: "www-data", group: "www-data"
  </code></pre>
  
  <p><strong>2. Artisan can only be run from inside the vagrant box to have access to the DB</strong></p>
  
  <p>Fine, <code>vagrant ssh</code> and run artisan from the www folder.</p>
  
  <p><strong>3. app/storage &amp; app/database have to be writable by the vagrant user in order to use migrations</strong></p>
  
  <p>Grrr, ok, added the following awful piece of code to the vagrant file (note, tried to do this in Puppet first and it didn't take):</p>
  
  <pre><code>config.vm.provision :shell, :inline =&gt;
    "usermod -a -G www-data vagrant"
  </code></pre>
  
  <p><strong>4. app/storage &amp; app/database are not writeable by the group</strong></p>
  
  <p>Argh!!! Ok, let's try this Puppet directive:</p>
  
  <pre><code>file { "/var/www/app/storage":
    source =&gt; "/var/www/app/storage/",
    mode =&gt; 0775,
    ensure  =&gt; 'directory',
    owner   =&gt; 'www-data',
    group   =&gt; 'www-data',
    recurse =&gt; true
  }
  </code></pre>
  
  <p>Nope, doesn't work. Tried to do the same with the Puppet <code>exec {}</code> directive to no effect. It seems that permissions for the vagrant synced folder are set by the host machine, not the guest.</p>
  
  <p>Finally ended up manually changing the permissions for the folder in the host machine. Is there any simpler way to do this? I would really just like to be able to give the next dev a  worry free environment they can clone from the repo, not have them re-setup everything after cloning.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>We've figured out that if we change the Apache run user, vagrant doesn't override it on reload. So we've done that manually and it's working better than changing the synced folder's permissions &amp; owner. Now we're just trying to figure out how to make that change manually in Puppet.</p>