Last Updated: August 26, 2020
·
7.288K
· ssteynfaardt

Enable apache writable files with Vagrant

Enable Apache writable files.

Depending on the web application apache might need to be able to create new files or directories, this is very much the case when using frameworks like Laravel, Yii or Symphony…

All you need to do is assign the www-data user as the file and group owner, for the directory where your apapche web root is located, usally this is /var/www

Make sure the vagrant is not running: vagrant halt

Open your Vagrantfile in an editor.

Now add :owner => "www-data", :group => "www-data" to config.vm.synced_folder

If you are still using v1 config files, add it to config.vm.share_folder

The complete command should look simular to the code below, make sure to update the path /location/to/locahost/sites

Vagrant.configure("2") do |config|
  #...
  config.vm.synced_folder "/location/to/locahost/sites", "/var/www", id: "vagrant-root", :owner => "www-data", :group => "www-data"
  #...
end

Save the file.
run vagrant up
Now if you use vagrant ssh and look at /var/www the owner and group should be www-data and apache will be able to create new files and directories.

3 Responses
Add your response

Thanks a lot!!! Very helpfully!!

over 1 year ago ·

thanks! it worked really well!

over 1 year ago ·

4 years later, you saved my butt. thank you!

over 1 year ago ·