windows下安装vagrant和宝塔面板
今天小编换了台电脑后在windows下安装vagrant
记录下安装过程
废话少叙,直接上干货
一、安装VirtualBox
首先到 VirtualBox 官网下载最新版本的 VirtualBox ,之后双击安装就好了,过程很简单。
二、安装Vagrant
还是到 Vagrant 官网下载最新版本的 Vagrant ,安装方法同上。
三、安装VagrantBox
我们可以到 VagrantBox 下载自己需要的 box 文件,我比较习惯用 Ubuntu ,所以下载了列表中的第一个。与其说是下载,
不如说是 .box 文件的使用方法。方法如下:
在你的工作目录创建一个新的文件夹,打开终端,cd 到新建的文件夹中,输入
vagrant init 你的box名称
比如vagrant init laravel/homestead
,这时会在文件夹中新建一个名为 vagrantfile 的文件,这里面包含了这个box的一切配置信息。还是在上面的文件夹中,终端输入
vagrant up
启动 vagrant ,由于是第一次安装,所以时间会比较长,个人推荐将下载地址复制下来用其他下载软件比如 FDM 来下载 box 文件比较快。
如果是用其他软件下载的 box 文件,下载完之后需要在终端执行
vagrant box add '你给box起的别名' box文件名
来添加新的 box ,再执行vagrant init '你给box起的别名'
来初始化 box ,最后再执行vagrant up
启动虚拟机。
四、Vagrant配置
刚才的文件夹中有一个名为 vagrantfile 的文件,它包含了此 box 的配置。打开文件,我们需要对它进行一些简单的配置
找到
config.vm.network "private_network", ip: "192.168.33.10"
这一行,将其前面的 “#” 去掉,这样做的目的是我们可以通过这个IP地址来访问虚拟机而不是通过端口转发,这样会方便一些。
找到
config.vm.synced_folder "../data", "/vagrant_data"
,这一行配置的是共享目录,也就是将你的工作目录和虚拟机的网站目录共享,前面的是本地目录,后面的是虚拟机中的目录,
下面是我的配置
config.vm.synced_folder "/Users/myname/Workspace/WebProgram" , "/www/wwwroot" , owner:"www" , group:"www" , create:true , mount_options:["dmode=755","fmode=664"] config.vm.synced_folder ".", "/vagrant", disabled: true
找到
config.vm.provider "virtualbox" do |vb| # # Display the VirtualBox GUI when booting the machine # vb.gui = true # # # Customize the amount of memory on the VM: vb.memory = "2048" end
这几行配置的是虚拟机的内存,可以根据自身需求进行调整。
大概配置完成后就可以 vagrant up
打开虚拟机了。
PS:之后每次对配置文件进行更改时,都需要重载 box ,重载命令 vagrant provision && vagrant reload
。
下面 就可以去宝塔官方网站安装宝塔面板了
如下:小编是centos7
yum install -y wget && wget -O install.sh http://download.bt.cn/install/install_6.0.sh && sh install.sh
如果启动出现如下错误
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: mount -t vboxsf -o uid=1000,gid=1000 vagrant /vagrant The error output from the command was: mount: unknown filesystem type 'vboxsf'
运行如下命令解决:
vagrant plugin install vagrant-vbguest vagrant reload --provision