首页 > 解决方案 > 我可以在 Vagrant 中安装共享文件夹之前强制进行配置吗?

问题描述

我有以下内容Vagrantfile

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.box = "centos/6"
  config.vm.provision :shell, :path => "bootstrap.sh"
  config.vm.network :forwarded_port, host: 8080, guest: 80
  config.vm.network :forwarded_port, host: 3306, guest: 3306
  config.vm.synced_folder "../../applications", "/var/www/html", :owner=>"apache", :group=>"apache"

  config.vm.provider :virtualbox do |vb|
      vb.customize ["modifyvm", :id, "--memory", 2048]
      vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
      vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
      vb.name = "appserver"
   end
end

每次我运行vagrant up(第一次,假设我第一次运行vagrant destroy -f)我最终都会出现以下错误:

==> default: Mounting shared folders...
    default: /vagrant => E:/Development/vagrant/centos6
    default: /var/www/html => E:/Development/applications/arx
Vagrant was unable to mount VirtualBox shared folders. This is usually
because the filesystem "vboxsf" is not available. This filesystem is
made available via the VirtualBox Guest Additions and kernel module.
Please verify that these guest additions are properly installed in the
guest. This is not a bug in Vagrant and is usually caused by a faulty
Vagrant box. For context, the command attempted was:

id -u apache    
The error output from the command was:    
id: apache: No such user

错误很明显“apache 用户不存在”。正如我所看到的,有两种或“三种”方法可以解决此问题:

有谁知道这是否可行,如果可以,怎么办?我无法找到有关第三种解决方案的任何信息 :( 如果您有更好的解决方案,非常欢迎您在这里发帖,它可能会对我和其他人有所帮助。

我找到了这个这个,但没有帮助。

标签: vagrantprovisioningvagrantfilevagrant-provision

解决方案


一种可能的解决方案是将 apache 作为 vagrant 用户运行。

在您的/etc/httpd/conf您可以将用户和组值替换为

User vagrant
Group vagrant

因此您可以继续与 vagrant 用户共享您的文件夹,并且 httpd 将作为 vagrant 用户运行。


推荐阅读