Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 783
envysea Avatar asked Oct 15 '14 02:10

envysea


2 Answers

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

like image 195
Jesse Overright Avatar answered Jan 04 '23 00:01

Jesse Overright


To expand upon the answer of Jesse, when using homestead (and thus Homestead.yaml) you can pass these options through like this

folders:
- map: ./
  to: /home/vagrant/code
  options:
    mount_options: ['dmode=777','fmode=777']

Based on https://laravel.com/docs/5.8/homestead#configuring-homestead and https://www.vagrantup.com/docs/synced-folders/basic_usage.html#modifying-the-owner-group

like image 33
Ken Avatar answered Jan 03 '23 22:01

Ken