使用nfs解决Homestead 运行 Laravel 本地项目响应缓慢问题

vagrant up启动虚拟机后运行命令安装nfs

$ vagrant plugin install vagrant-winnfsd

文件 1:homestead/scripts/homestead.rb

    # Register All Of The Configured Shared Folders
 if settings.include? 'folders'
  settings["folders"].sort! { |a,b| a["map"].length <=> b["map"].length }

  settings["folders"].each do |folder|
    config.vm.synced_folder folder["map"], folder["to"],
    id: folder["map"],
    :nfs => true,
    :mount_options => ['nolock,vers=3,udp,noatime']
   end
  end

    # Change PHP CLI version based on configuration
    if settings.has_key?('php') && settings['php']
      config.vm.provision 'shell' do |s|
        s.name = 'Changing PHP CLI Version'
        s.inline = "sudo update-alternatives --set php /usr/bin/php#{settings['php']}; sudo update-alternatives --set php-config /usr/bin/php-config#{settings['php']}; sudo update-alternatives --set phpize /usr/bin/phpize#{settings['php']}"
      end
    end

    # Creates folder for opt-in features lockfiles
    config.vm.provision "shell", inline: "mkdir -p /home/vagrant/.homestead-features"
    config.vm.provision "shell", inline: "chown -Rf vagrant:vagrant /home/vagrant/.homestead-features"

    # Install opt-in features
    if settings.has_key?('features')
      settings['features'].each do |feature|
        feature_name = feature.keys[0]
        feature_variables = feature[feature_name]
        feature_path = script_dir + "/features/" + feature_name + ".sh"

        # Check for boolean parameters
        # Compares against true/false to show that it really means "<feature>: <boolean>"
        if feature_variables == false
          config.vm.provision "shell", inline: "echo Ignoring feature: #{feature_name} because it is set to false \n"
          next
        elsif feature_variables == true
          # If feature_arguments is true, set it to empty, so it could be passed to script without problem
          feature_variables = {}
        end

        # Check if feature really exists
        if !File.exist? File.expand_path(feature_path)
          config.vm.provision "shell", inline: "echo Invalid feature: #{feature_name} \n"
          next
        end

        config.vm.provision "shell" do |s|
          s.name = "Installing " + feature_name
          s.path = feature_path
          s.env = feature_variables
        end
      end
    end

将以上代码替换成下面的:

if settings.include? 'folders'
  settings["folders"].sort! { |a,b| a["map"].length <=> b["map"].length }

  settings["folders"].each do |folder|
    config.vm.synced_folder folder["map"], folder["to"], 
    id: folder["map"],
    :nfs => true,
    :mount_options => ['nolock,vers=3,udp,noatime']
  end
end

文件 2:Homestead.yaml

folders:
    - map: ~/Code
      to: /home/vagrant/Code
      type: "nfs"

最后运行vagrant reload --provision重启即可

zed
请先登录后发表评论
  • latest comments
  • 总共1条评论
zed

zzzzzzzz:66666666

2020-10-02 23:00:57 回复