总结之二 Vagrant搭建本地环境

因为工作需要 在本地搭建一个开发环境 但是在搭建中发现不是一帆风顺 所以记录下来

详细的搭建过程 可以看这篇github上的文章 介绍的很详细,我也不做多余的重复工作了。

下面我就讲一下遇到的问题:
经过了成功执行vagrant init,生成了Vagrantfile文件,也修改了你们的ip地址,可是执行vagrant up却如下错误:

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Clearing any previously set network interfaces...
There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.

Command: ["hostonlyif", "create"]

Stderr: 0%...
Progress state: E_FAIL
VBoxManage.exe: error: Failed to create the host-only adapter
VBoxManage.exe: error: Could not find Host Interface Networking driver! Please reinstall
VBoxManage.exe: error: Details: code E_FAIL (0x80004005), component HostNetworkInterfaceWrap, interface IHostNetworkInterface
VBoxManage.exe: error: Context: "enum RTEXITCODE __cdecl handleCreate(struct HandlerArg *)" at line 94 of file VBoxManageHostonly.cpp

因为这里用的VirtualBox版本是5.1.22-115126-Win,这似乎是VirtualBox本身的一个bug 。换了一版本就可以了。我重新选择了
VirtualBox的4.3.40-110317-Win,不过这个版本现在官方已经不支持了,看自己的选择吧

二 项目迁入

成功配置好了环境后,当我把项目迁入当前环境,执行composer update或者访问我的项目时,出现了下面这个报错:

mmap() failed: [12] Cannot allocate memory

mmap() failed: [12] Cannot allocate memory
PHP Fatal error:  Out of memory (allocated 516435968) (tried to allocate 4096 bytes) in /vagrant/0623/vendor/fukuball/jieba-php/src/vendor/multi-array/MultiArray.php on line 64

mmap() failed: [12] Cannot allocate memory
PHP Fatal error:  Out of memory (allocated 516435968) (tried to 

一看就知道是环境的内存大小超出了,所以我就修改了环境中的php.ini文件,但是还是不行。不论我给开多大的内容。

之后有了另一个思路:

我的这个vagrant搭建时的虚拟机内存大小是否不够,因此,找到了Vagrantfile配置文件,

  # 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 = "1024"
  # end

修改为

   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 = "4096"
   end

重新访问我的项目,成了!。

三 vagrant权限问题

在vagrant初始化后,会发现/vagrant的权限是777,甚至之后该目录下的文件权限也是777,进行修改权限会发现修改不了。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 虚拟开发环境 在项目开发中,我们经常会遇到各种各样的问题,需要使用虚拟开发环境来完成,虚拟和正式环境一样的虚拟开发...
    sunnyaxin阅读 11,598评论 4 6
  • 开发需要在各种系统上进行开发任务,运维则需要在各种系统上学习工具使用。因此,虚拟机恐怕也是 IT 人员最常使用的工...
    李广慧阅读 10,879评论 3 24
  • 接收自己的一开始的做不好,认识到自己现在所处的周期的低谷,才能有更好的心态,才有持续做下去的动力。 昨天工作上遇到...
    李灿辉阅读 1,215评论 0 0
  • 坏比好重要。 对世界上绝大多数工作来说,该做什么早就有人设计好了,你就算有损失厌恶也用不上。但是有一类工作却要求我...
    南有乔木faith阅读 981评论 0 0
  • 迷上了Tayler Swift You're so gorgeous!
    Raven掠夺者阅读 1,007评论 0 1