解决 Windows 系统使用 Homestead 运行 Laravel 本地项目响应缓慢问题
注意: 此方法可能带来未知副作用,请操作之前务必备份原配置文件!!
使用 win7 电脑学习第二本教程,发现项目运行起来切换页面每次都要 7-10 s,很不正常啊,部署到服务器发现加载仅需要 200 ms 左右。
尝试过增加虚拟机配置, 但是没有任何效果, 经过验证也不是数据库的原因,通过网上查询了解到, 是因为 VirtualBox 的 IO 引起的。
解决方案是安装NFS Plugin
,参考文章(英文)
英文不好的小伙伴接着看 ~
首先,命令行进入 Homestead 启动 vagrant
> cd ~/Homestead && vagrant up
然后运行安装命令
$ vagrant plugin install vagrant-winnfsd
如上图,安装成功后修改配置文件
修改配置文件前建议先备份,以免修改后出现问题!
文件1:homestead/scripts/homestead.rb
# Register All Of The Configured Shared Folders
if settings.include? 'folders'
settings["folders"].each do |folder|
if File.exists? File.expand_path(folder["map"])
mount_opts = []
if (folder["type"] == "nfs")
mount_opts = folder["mount_options"] ? folder["mount_options"] : ['actimeo=1', 'nolock']
elsif (folder["type"] == "smb")
mount_opts = folder["mount_options"] ? folder["mount_options"] : ['vers=3.02', 'mfsymlinks']
end
# For b/w compatibility keep separate 'mount_opts', but merge with options
options = (folder["options"] || {}).merge({ mount_options: mount_opts })
# Double-splat (**) operator only works with symbol keys, so convert
options.keys.each{|k| options[k.to_sym] = options.delete(k) }
config.vm.synced_folder folder["map"], folder["to"], type: folder["type"] ||= nil, **options
# Bindfs support to fix shared folder (NFS) permission issue on Mac
if Vagrant.has_plugin?("vagrant-bindfs")
config.bindfs.bind_folder folder["to"], folder["to"]
end
else
config.vm.provision "shell" do |s|
s.inline = ">&2 echo \"Unable to mount one of your folders. Please check your folders in Homestead.yaml\""
end
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
重启 Homestead 使配置文件生效,大功告成。再次运行项目响应时间已经正常了,希望帮助有相同情况的小伙伴!
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /boutique/detail/tanhehebie
系列文章
更多
同类精品
更多
-
photoshop保存的图片太大微信发不了怎么办
PHP中文网 06-15 -
《学习通》视频自动暂停处理方法
HelloWorld317 07-05 -
Android 11 保存文件到外部存储,并分享文件
Luke 10-12 -
word里面弄一个表格后上面的标题会跑到下面怎么办
PHP中文网 06-20 -
photoshop扩展功能面板显示灰色怎么办
PHP中文网 06-14 -
微信公众号没有声音提示怎么办
PHP中文网 03-31 -
excel下划线不显示怎么办
PHP中文网 06-23 -
excel打印预览压线压字怎么办
PHP中文网 06-22 -
TikTok加速器哪个好免费的TK加速器推荐
TK小达人 10-01 -
怎样阻止微信小程序自动打开
PHP中文网 06-13