Cannot change permissions of folders within vagrant home folder

前端 未结 7 2102
抹茶落季
抹茶落季 2020-12-04 08:50

When I ssh in to my vagrant vm, I can change permissions of files and folders above and outside the vagrant user folder, and for files within the vagrant user folder. But ca

7条回答
  •  春和景丽
    2020-12-04 09:18

    VirtualBox doesn't allow changing the owner/permissions for synced folders.

    You can change it in the Vagrant file (as answered by others).
    Consider changing the owner instead of the group.
    Consider also that - if done so that your server can write to files - your server is likely called www-data instead of httpd. Use ps aux | grep nginx [or apache / lighthttpd] to check.

    There are some other options:

    • Change the owner of the program that is accessing the shared files instead of the synced folder.
      For example, if PHP needs to write to file, change the server and PHP to run as vagrant. [In Apache, that's done in httpd.conf. NGINX's user is set in nginx.conf, php-fpm's user is in php-fpm.conf or one of the files it includes.
      You need to change the permissions on the Apache lockfile (/var/lock/apache2) or PHP websocket file (/var/run/php5-fpm.sock)] and webserver.
    • Use a different VM (HyperV, VMware) instead of VirtualBox. Other VM's dont seem to have this restriction.
    • Use RSyn to sync files instead of using the default syncing.
      config.vm.synced_folder "/var/www/", type: "rsync"
    • Set all the permissions to 777. Normally this would disastrous and not even a suggestion. It's still a bad idea, but on a VM is possibly doable. Think twice before giving shared access though.
      config.vm.synced_folder "/var/www/", mount_options: ["dmode=777", "fmode=666"]

    These answers are better described by Ryan Sechreset and Jeremy Kendall.

提交回复
热议问题