vagrant集成thinkphp开发环境

11 篇文章 0 订阅
10 篇文章 0 订阅

vagrant集成thinkphp开发环境

1. 本地环境设置

1.1 编辑器:

建议使用sublime Text 3,会有单独文档来说明如何使用Sublime Text高效开发php。

1.2 putty

putty是免费的ssh客户端,登录homestead虚拟机的利器。
点击这里下载。
注意 如果不使用putty登录,用homestead ssh登录,也可以。

2. vagrant 集成开发环境安装配置

2.1 vagrant下载安装

vagrant是一个虚拟机管理工具。在添加虚拟机后,可以启动虚拟机的镜像,如果出现错误,可以随时销毁重建开发环境。

这里 下载。下载后直接安装。
vagrant安装确认:

C:\>vagrant --version
Vagrant 1.7.2

2.2 virtualbox 安装

virtualbox是作为vagrant的一个provider,安装后,在启动homestead时候,vagrant会自动启动virtualbox。
这里 下载,下载直接安装。
vagrant和virtualbox 版本对应使用:vagrant (1.8.3) 对应 virtualbox(5.0.30或者5.1.34)

2.3 下载box

下载linux box,我这边就是用centos 7.0 为例子,下载地址:https://github.com/tommy-muehle/puppet-vagrant-boxes/releases/download/1.1.0/centos-7.0-x86_64.box
也可以自己找喜欢的box:点击这里

2.4 添加box到vagrant管理

进入你下载存放目录:D:\Mark\box_list
执行命令:

dir
驱动器 D 中的卷是 软件
卷的序列号是 2420-CC59
D:\Mark\box_list 的目录
2018/03/17 11:31

.
2018/03/17 11:31 ..
2018/03/17 11:13 498,180,608 centos-7.0-x86_64.box
1 个文件 498,180,608 字节
2 个目录 39,126,568,960 可用字节

这里已经存放了下载好的box,下面就可以去添加box了。
vagrant 的相关命令:

  1. vagrant box list: 查询box列表
  2. vagrant box add: 添加box到vagrant 管理
  3. vagrant box remove: 移除box
    下面,我们把这个centos 7.0 box 添加到vagrant
vagrant box add centos-7.0-x86_64.box

这里写图片描述
这样box就添加成功了。
vagrant 命令进阶:
1. vagrant init : 初始化配置vagrantfile
2. vagrant up : 启动虚拟机
3. vagrant ssh: ssh 登录虚拟机
4. vagrant suspend: 挂机虚拟机
5. vagrant reload: 重启虚拟机
6. vagarnt halt: 关闭虚拟机
7. vagrant status: 查看虚拟机状态
8. vagrant destory: 删除虚拟机

3. 启动,配置虚拟机

3.1 初始化虚拟机:

这里写图片描述
vagrant 的配置文件已经有了。
Vagrantfile 推荐设置

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

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
  # The most common configuration options are documented and commented below.
  # For a complete reference, please see the online documentation at
  # https://docs.vagrantup.com.

  # Every Vagrant development environment requires a box. You can search for
  # boxes at https://atlas.hashicorp.com/search.
  config.vm.box = "CentOS"
  config.vm.hostname = "CentOS"
  config.vm.network "private_network", ip: "192.168.10.10",auto_config: true
  config.vm.synced_folder "F:/workspaces/duchuang/duchuang/", "/data/wwwroot/default/duchuang/"

  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"
      vb.cpus = 2
      vb.name = "CentOS"
  end

  # Disable automatic box update checking. If you disable this, then
  # boxes will only be checked for updates when the user runs
  # `vagrant box outdated`. This is not recommended.
  # config.vm.box_check_update = false

  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine. In the example below,
  # accessing "localhost:8080" will access port 80 on the guest machine.
  # config.vm.network "forwarded_port", guest: 80, host: 8080

  # Create a private network, which allows host-only access to the machine
  # using a specific IP.
  # config.vm.network "private_network", ip: "192.168.33.10"

  # Create a public network, which generally matched to bridged network.
  # Bridged networks make the machine appear as another physical device on
  # your network.
  # config.vm.network "public_network"

  # Share an additional folder to the guest VM. The first argument is
  # the path on the host to the actual folder. The second argument is
  # the path on the guest to mount the folder. And the optional third
  # argument is a set of non-required options.
  # config.vm.synced_folder "../data", "/vagrant_data"

  # Provider-specific configuration so you can fine-tune various
  # backing providers for Vagrant. These expose provider-specific options.
  # Example for VirtualBox:
  #
  # 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
  #
  # View the documentation for the provider you are using for more
  # information on available options.

  # Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
  # such as FTP and Heroku are also available. See the documentation at
  # https://docs.vagrantup.com/v2/push/atlas.html for more information.
  # config.push.define "atlas" do |push|
  #   push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
  # end

  # Enable provisioning with a shell script. Additional provisioners such as
  # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
  # documentation for more information about their specific syntax and use.
  # config.vm.provision "shell", inline: <<-SHELL
  #   apt-get update
  #   apt-get install -y apache2
  # SHELL
end

3.2 启动vagrant

使用命令:vagrant up 启动vagrant
如果看到如下图,恭喜你,已经成功了。
这里写图片描述
就可以进入虚拟机看看了。
这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

菜鸟没翅膀

你的打赏是我最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值