Search code examples
permissionsvagrantfile-permissions

Application can't create a writable folder with Vagrant


I configured my own basic Vagrant Box from Vagrant's Official Precise64 box. I have a synced folder located here "/var/www" and the public folder located at "/var/www/public".

For "/var/www", my permissions are:

drwxr-xr-x  1 vagrant vagrant 

For "/var/www/public", my permissions are:

drwxr-xr-x  1 vagrant vagrant

To illustrate my issue, with WordPress applications, I have manually set the permissions of uploads to 777. WordPress is able to create a folder inside of uploads for the month, such as "/var/www/public/wp-content/uploads/10/"; however, it can't upload or write to the folder it just made unless I again manually change the permissions of the newly created "10" folder to be writable.

This happens with all applications such as Laravel's "storage" folder and basically anytime a program tries to create a directory. Trying to force the permissions to set on Vagrant Up during provisioning is also not working:

config.vm.synced_folder "/path/to/writable/folder", "/path/to/writable/folder", :mount_options => ["dmode=777","fmode=666"]

So, what permissions do I need to set on virtual server to enable this to work?


Solution

  • I've used both WordPress and Laravel in Vagrant and set write permissions in the Vagrantfile:

    config.vm.synced_folder ".", "/vagrant", :mount_options => ['dmode=774','fmode=775']

    And also add the default Apache user to the vagrant group (I use shell provisioning):

    usermod -a -G vagrant www-data