Home  >  Article  >  Backend Development  >  windows安装vagrant 以及 laravel homestead

windows安装vagrant 以及 laravel homestead

WBOY
WBOYOriginal
2016-06-20 12:57:101001browse

之前一篇文章介绍了composer的安装,本篇介绍一下vagrant以及homestead的安装。

原文:ekan001.com/article/40

准备工作

VirtualBox 虚拟机,基础依赖 Vagrant 基于VirtualBox或vmware的虚拟化环境部署工具,可以将一个虚拟机打包(简称vbox)给别人。 Homestead laravel官方vbox,集成环境以及一套特制的命令行工具。 xshell 这是一款windows下的ssh & shell工具,同类的有securecrt、putty等。

安装VirtualBox

这个安装比较简单,百度一下,下载安装即可。

安装Vagrant

到 https://www.vagrantup.com/downloads.html 下载,速度有点慢,忍受一下吧。安装过程同样傻瓜化,略过。

安装完以后重启一下,再打开cmd,vagrant --version 命令应该生效了。

下载Homestead vbox

通过命令

vagrant box add laravel/homestead https://atlas.hashicorp.com/laravel/boxes/homestead

可以自动下载homestead的vbox,然而国内网络大家懂的,龟速。

建议自己有vps的同学,在vps上通过

wget -O homestead.box https://atlas.hashicorp.com/laravel/boxes/homestead/versions/0.2.6/providers/virtualbox.box

手动下载后,再从vps上将box下载到本地,或者可以试试用迅雷下载。总之,想办法把这个box文件下载下来,然后通过以下命令添加到vagrant

vagrant box add ./homestead.box

./homestead.box 是box文件所在路径,我这里是直接 cd 到文件所在目录中执行命令的。

添加过程中可能会让你选virtualbox或vmware,很明显选virtualbox.其他默认即可。

安装homestead命令行工具

通过composer安装homestead命令行工具

composer global require "laravel/homestead=~2.0"

关于composer这块,前面一篇文章《windows安装composer》介绍的比较详细,不明白的可以去看一下。

然后执行

homestead init

会在 ~/.homestead/ 下面生成一个 Homestead.yaml 文件,你可以手动编辑它,也可以通过命令

homestead edit

编辑它。

配置

可以看到,Homestead.yaml 中有一系列参数,参数含义在laravel官方手册里介绍的比较详细,这里不再赘述。有什么不明白可以留言。

启动

通过cmd执行

homestead up

即可启动虚拟机。

连接ssh

打开 xshell ,创建一个新的链接:

地址:127.0.0.1 端口:2222 用户身份验证方式:public key 用户名:vagrant 用户密钥:通过ssh-keygen工具生成 id_rsa 文件。

完结

整个环境搭建完毕,之后就开心写代码吧。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn