Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

tzookb's avatar

vagrant permissions and foldering

I love working with vagrant but I noticed I'm wasting a lot of time because permiisions stuff.

I understant that vagrant doesnt let you alter permissions in shared folders, so how do I handle the permissions of app/storage for example....

as that laravel need r/w/x permissions there.

I currently use this --> config.vm.synced_folder "/Users/tzookb/Docs/", "/web", create: true, owner: "vagrant", group: "www-data", mount_options: ["dmode=775,fmode=664"]

I could simply change the: dmode fmode to 777 both, but I think this is the easy solution, instead of the right one

0 likes
4 replies
DivDax's avatar

i use this to sync folders:

config.vm.synced_folder ".", "/var/www", :nfs => true

to take effect you to have to restart your vm.

tzookb's avatar

and what that means the nfs true, isnt that only the synced folders method?

fideloper's avatar
Level 11

If you share folders with the default syncing method, the owners of those directories is usually "vagrant".

Apache/Nginx and PHP-FPM (if you use Ubuntu) usually run as user and group "www-data". The shared directory, however, is owned by Vagrant. This means you likely need to set permissions of the shared directories they are writing to so that "all others" can write to them. However the default sync is a little weird in that the share settings need to be set from the host machine, not the guest VM, so it's a little wonky to set them.

In this setup, and only for development, I usually have Nginx / PHP-FPM (or Apache if you use that instead) run as user/group "vagrant", so that they can freely write to the shared directory which is owned by that user/group. Those settings are in /etc/php5/fpm/pool.d/www.conf for PHP-FPM and /etc/apache2/envvars for Apache (generally you won't need to change Nginx's configuration).

NFS, on the other hand, is "network files share". In this scenario, your host machine is the filer server, and the vagrant VM is the client connecting to the file server. The shared files (when I use NFS on my mac) are usually owned by a number (502 or there about) and a group of "share" or something similar. These are actually the UID (user ID) and group name used by user of your Macintosh - so technically the directories are owned by the user and group of the host computer. There's a bit more to it, but the net effect is that your application won't have a problem writing to those directories - thus the proposed solution above will work.

NFS can sometimes "lag" behind when updates are made to files (making things like file watchers for asset updates frustrating), however default sync tends to slow down with large number of files being shared. Choose your poison.

5 likes

Please or to participate in this conversation.