Search code examples
phpvagrantfile-permissionsmkdir

Vagrant and PHP "mkdir"


If having some problems with PHPs mkdir function when in a Vagrant box.

What happens is the following, I create a folder:

mkdir('path/to/directory', 0775, true);

This succesfully creates the folder with the following permissions on my Vagrant box:

drwxrwxr-x 1 www-data vagrant directory

and the following on my local machine:

drwxr-xr-x  3 root staff directory

On my local machine however (where I'm actually going to do stuff with the file) I can't edit the files within the folder and PHPStorm shows a lock at the directory.

When I do something like file_put_contents() to create a file and chmod that file to 0664 or 0775 I can edit it.

Any help would be appreciated.

I already tried an extra chmod on the directory, didn't work.


Solution

  • Turned out my Vagrant box was build with sudo, hence the directory was from root instead of my own user.