7

I am using vagrant to run my vm using ubuntu, apache, etc. This is running on my OSX host.

Everything works fine until my php application tries to create a folder, files within that folder, etc. I get Permission denied. What am I missing on the provision / configuration of the vagrant file?

1
  • Can you post your Vagrantfile for us to see. I use Vagrant for PHP dev and might be able to help
    – fullybaked
    May 16, 2013 at 12:00

3 Answers 3

25

in this case, if you're using Vagrant + Apache2.

the solution is:

  1. edit /etc/apache2/apache2.conf;
  2. Search for User and Group directives
  3. Change these lines to:

    User vagrant
    Group vagrant
    
  4. run sudo service apache2 restart

its not possible to change /vagrant directory owner to www-data (apache user);

Anyway, it works for me.

4
  • 1
    This is what I did. I also needed to change the group on the session data folder so PHP could properly read / write session data (on CentOS): chown root:vagrant /var/lib/php/session. I deleted existing session in that session folder, and everything worked fine after that.
    – chris
    Nov 7, 2013 at 21:17
  • Which apache? The one on the host machine or guest VM? Feb 26, 2015 at 20:36
  • Guest Virtual Machine. Feb 27, 2015 at 13:42
  • It's worth noting that on Ubuntu 16.10 (and possibly 16.04) Vagrant started using the 'ubuntu' user and group instead of 'vagrant'. The answer is still a valid solution to the problem, just change the user/group. Jan 3, 2017 at 3:38
5

Edit Vagrantfile

  config.vm.synced_folder "./", "/var/www", owner: "www-data", group: "www-data"
0
2

You need to set the owner on the folder that php is trying to write to, to the apache user which is normally www-data... ssh into the vagrant box and try:

sudo chown www-data:www-data <dirname>

That should work... if it does then just add that to what ever provisioner you are using.

2
  • 1
    Yep, and an alternative (but similar) approach is to run Apache as the vagrant user. I've done this successfully.
    – Jonathan
    May 30, 2013 at 1:53
  • 3
    Jonathan it would be handy to have that as an answer
    – Adam Waite
    Jul 9, 2013 at 9:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.